几个基础的SQL语句

选课表tSC,学生表tStu,课程表tCou


1.求选课人数<10的课程(group,hanving 的用法)

select tSC.cname ,count(sno) from tSC Group by tSC.cno having count(*)>3

2.学生成绩表(连接)

select tStu.sname,tSC.cname,tSC.score from tStu,tSC where tStu.sid=tSC.sid

3.每门课的先行课(自连接)

select First.cno,Second.cpno from tCou First,tCou Second Where First.cpno=Second.cno

4.找和刘晨一个系的的学生(=)

select tStu.sname from tStu where tStu.sdept=(select sdept from tStu where sname='刘晨')

5.查找比信息系所有年龄都小的学生姓名(<,<>)

select sname from tStu where sage<(select MIN(sage) from tStu where sdept='IS') and sdept<>'IS'

6.查询选修过1号课程的学生名字(exists)

select sname from tStu WHERE EXISTS (select * from tSC where sid=tStu.sid AND cid='1')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值