student表: course表:
查询:选课数大于等于三门的学生姓名
1.使用嵌套查询
SELECT name from student WHERE id in
(SELECT id from course GROUP BY id HAVING COUNT(course)>=3)
结果
嵌套查询子查询中只能有一列数据并且与主查询中的条件列相同。
2.使用连表查询
SELECT name from student s,course c where s.id=c.id GROUP BY c.id HAVING COUNT(course)>=3;
结果同上 查询时关键字顺序为