首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

小弟我是新人,解法

2012-01-28 
我是新人,求一个解法我有个表T姓名课程成绩张三语文60李四语文50张三数学70李四数学80我想查找所有课程成

我是新人,求一个解法
我有个表T
姓名   课程   成绩
张三   语文   60
李四   语文   50
张三   数学   70
李四   数学   80

我想查找所有课程成绩> =60的学生姓名
如果解

[解决办法]
select distinct 姓名 from table where 成绩 > = 60
[解决办法]
抱歉,更正一下:
declare @t table(姓名 varchar(10),课程 varchar(10),成绩 int)
insert @t
select '张三 ', '语文 ', 60 union all
select '李四 ', '语文 ', 50 union all
select '张三 ', '数学 ', 70 union all
select '李四 ', '数学 ', 80

----查询
SELECT 姓名 FROM(
select 姓名 from @t where 成绩 > = 60
group by 姓名,课程) AS t
GROUP BY 姓名 having count(*) = (select count(DISTINCT 课程) from @t)


/*结果
姓名
----------
张三
*/
[解决办法]
create table test(姓名 varchar(10),课程 varchar(10),成绩 int)
insert test select '张三 ', '语文 ',60
union all select '李四 ', '语文 ',50
union all select '张三 ', '数学 ',70
union all select '李四 ', '数学 ',80

select distinct 姓名 from test a
where not exists(select 1 from test where 姓名=a.姓名 and 成绩 <60)

drop table test

姓名
----------
张三
[解决办法]
后边有个a 是test这个表的别名!
就想select A AS 成绩一样的意思!·

热点排行