您的位置:首页 > 职场人生

java面试中关于学员一些sql语句的写法

2011-03-08 15:15 501 查看
1:查询选修课程为computer的学员名字

select name from stutents where sid
in(select sid from chengji,kecheng where chengji.kid=kecheng.kid and
kecheng.name='comput')
 

2:查询没有选修课程为c#的学员名字

select name from stutents where sid not in(
select sid from chengji,kecheng where
chengji.kid=kecheng.kid and kecheng.name='c#')
 

3:查询选修了所有课程的学员名字

select name from stutents where sid in (select sid from chengji right join kecheng on chengji.kid=kecheng.kid group by sid having count(*)=(select count(*) from kecheng))
 

4:查询选修了课程的学员名字

select 人数=count(distinct sid) from chengji
 

5:查询选修课程最少3门的学员名字

select name from stutents where sid in(
select sid from chengji group by sid
having count(distinct kid)>=3)
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  面试 java sql c# join