SQL:选择没有嵌套查询的查询
我有下一个输入数据, 我需要编写两个表
create table Courses(
id number(19) not null,
name varchar(100),
);
create table Students (
id number (19) not null,
name varchar(100),
course_id number (19) not null,
);
来获取所有学生人数(例如超过 10 人)的课程 所以,我写了带有嵌套查询的变体,如下所示
select distinct courses.name from student, courses where courses.id=student.courses_id and (select count(Students.id) from Students where student.course_id = course.id) > 10
!没有测试,只是写这篇文章,它是例子! 所以,我的问题是如何在没有嵌套查询的情况下编写相同的查询?
I have next input data,
There are two tables
create table Courses(
id number(19) not null,
name varchar(100),
);
create table Students (
id number (19) not null,
name varchar(100),
course_id number (19) not null,
);
I need to write query for get all cources with count of student for example more than 10
So, I've written variant with nested query like this
select distinct courses.name from student, courses where courses.id=student.courses_id and (select count(Students.id) from Students where student.course_id = course.id) > 10
!!! Didn't test, just wrote for this post, it is example!!!
So, My question is how to write the same query without nested query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
GROUP BY
/HAVING
子句:Use the
GROUP BY
/HAVING
clause:我会和
I would go with