1.查询名人表中性别是男的作者
select * from celebrity where ssex='男'
2.查询静夜思的作者
select celebrity.sname,works.wdynasty,summary.sassess from summary inner join celebrity on summary.sid=celebrity.sid inner join works on summary.wid = works.wid where works.wwork = '静夜思'
3.查询李白和杜甫的年纪
select sage from celebrity where sname='李白' or sname ='杜甫'
4.查询名人表中男女的个数
select count(*) from celebrity where ssex='男' select count(*) from celebrity where ssex='女' select count(*),ssex from celebrity group by ssex having ssex='男' or ssex='女'
5.查询白居易写的作品名称和对于的名句
select celebrity.sname,works.wwork,summary.sassess from summary inner join celebrity on celebrity.sid = summary.sid inner join works on works.wid = summary.wid where celebrity.sname = '白居易'
6.查询年纪在25到30岁之间的个数
select count(*) from celebrity where sage>25 and sage<30
7.查询名人表中最后两条的数据信息
select * from celebrity LIMIT 4,2;
8.查询李白的作品名称,名句和年纪
select celebrity.sage,works.wwork,summary.sassess from summary inner join celebrity on summary.sid = celebrity.sid inner join works on summary.wid = works.wid where celebrity.sname = '李白'
9.将作品为望岳的朝代修改为北宋
update works set wdynasty = '北宋' where wwork = '望岳'
10.新增名人表中的一个作者王维,年纪25,性别男
insert into celebrity values (7,'王维',29,'男')
1.查询sc表中对应何昊老师所教授课程的女生的信息
select s.*,c.cteacher from sc inner join s on sc.sno = s.sno inner join c on sc.cno = c.cno where s.sex = '女' and c.cteacher = '何昊';
2.-- 找出没有选修过何老师的课程的所有学生的姓名
select s.sname from s where not exists( select * from sc,c where sc.cno=c.cno and c.cteacher='何昊' and sc.sno=s.sno);
3.列出有不及格课程(成绩小于60)的学生的姓名
select DISTINCT S.sname from S inner join SC on S.sno = SC.sno where SC.scgrade<60; select s.sname from s where s.sno not in(select sno from sc where cno =1);
1.查询孙姓用户的个数
select count(*) from user where uname like '孙%'
2.查询年龄最大的两个用户名
select uname from user order by uage desc limit 0,2;
3.查询张三买的商品名
select product.pname from orders inner join user on orders.ouid = user.uid inner join product on orders.opid = product.pid where user.uname = '张三'
4.查询购买过电脑的用户名
select user.uname from orders inner join `user` on orders.ouid = `user`.uid inner join product on orders.opid = product.pid where product.pname = '电脑'
5.查询订单是909090对应的用户名和商品名
select user.uname,product.pname from orders inner join `user` on orders.ouid = `user`.uid inner join product on orders.opid = product.pid where orders.onumber = 909090
6.查询列表中最高价的前两条数据
select * from product order by pprice desc limit 0,2