Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64738
  • 博文数量: 44
  • 博客积分: 1985
  • 博客等级: 上尉
  • 技术积分: 505
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-14 16:54
文章分类

全部博文(44)

文章存档

2011年(1)

2008年(43)

我的朋友

分类: Mysql/postgreSQL

2008-06-16 01:51:02

题名是这样的:
studentname    classname      grade
 
 mike          english          65
 mike          math             75
 Jerry         english          80
 Jerry         math             68
 Lida          english          88
 Lida          chinese          77
 Lida          math             90
求出各科成绩都大于75分的学生。即得到如下结果

studentname    classname      grade
 Lida          english          88
 Lida          chinese          77
 Lida          math             90
20  修改 删除 举报 引用 回复
这个问题第1个回答:

SQL code
--> 测试数据: #

if object_id('tempdb.dbo.#') is not null drop table #

create table # (studentname varchar(5),classname varchar(7),grade int)

insert into #

select 'mike','english',65 union all

select 'mike','math',75 union all

select 'Jerry','english',80 union all

select 'Jerry','math',68 union all

select 'Lida','english',88 union all

select 'Lida','chinese',77 union all

select 'Lida','math',90



select * from # a where not exists (select 1 from # where studentname=a.studentname and grade<75)



/*

求出各科成绩都大于75分的学生。即得到如下结果

studentname    classname      grade

Lida          english          88

Lida          chinese          77

Lida          math             90 

*/


阅读(1346) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-04-09 18:33:58

是不是应该这样啊 select * from #cj where studentname not in (select dictinct studentname from #cj where grade<=75)

chinaunix网友2009-02-12 11:31:24

select * from #cj where studentname not in (select studentname from #cj where grade<=75)

chinaunix网友2008-11-02 16:42:25

楼上的解法巧妙

chinaunix网友2008-06-17 10:56:38

想了一下,弄了另外一个解决办法 select * from test2 where studentname not in(select studentname from test2 group by studentname having min(grade) <75);