摘要: 1查询出只选修了一门课程的全部学生的学号和姓名最初想法是select count(*)然后再去比较count(*),要是必就不会了select s_id ,sname from student,sc where sc.s_id=student.idgroup by sc.s_id,sname having count(*)=1;2查询同名同性学生名单,并统计同名人数开始是让sc的2个表来比较同名的,然后发现错了多比了几遍,然后又想把id也相同。但是错的更离谱select sname count(sname) from student group by id having count(sname 阅读全文
posted @ 2014-03-17 01:34 xxyyjj 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 查询各科成绩前三名的记录:(不考虑成绩并列情况)sc表,student表,course表比如某一科的前三名selcet score ,c_id from sc where c_id=1 order by score limit0,3;于是select from sc as s1 where s1.score in(select score from sc where s1.c_id=c_id group by c_id order by score desc limit0,3);但是这个出了问题,limit 不能有in,看网上说法可以再套一个select,但是有个问题是s1.c_id不认识.. 阅读全文
posted @ 2014-03-17 01:22 xxyyjj 阅读(164) 评论(0) 推荐(0) 编辑