多表联合查询问题
来源:互联网 发布:淘宝立体3d服装拍摄 编辑:程序博客网 时间:2024/05/21 14:52
数据库有如下三个表,每个表各个字段类型都是varchar2;
table1
table2
table3
(1)请设计一条sql语句,查出理科班的学生人数。
(2)请设计一条sql查询语句,查出所有理科班别的学生中每门课程的学习人数。
解答:
(1)由给出的数据表信息,知道要通过table1和table2来求得
方法1:用in
select count(student_name) from table2 where class_name in (select class_name from table1 where class_type='like')
方法2:用join
select count(student_name) from table2 t2 inner join table1 t1 on t2.class_name=t1.class_name where t1.class_type='like';
(2) 这题三个表都要用到
要统计一个字段对应不同值的个数;用group by
select major , count(student_name) num from table3 where student_name in (select count(student_name) from table2 where class_name in (select class_name from table1 where class_type='like')) group by major;
- 多表联合查询问题
- 多表联合查询分页问题
- sql多表联合查询的问题
- HQL多表联合查询的问题
- HQL多表联合查询的问题
- 双表联合查询问题
- 多表联合查询
- 多表联合查询
- 联合多表查询
- 多表联合查询
- 多表联合查询
- weiphp2.0:table多表联合查询的问题
- SQL Server两表联合查询问题
- SQL 多表联合查询
- Oracle多表联合查询
- php多表联合查询
- SQL 多表联合查询
- ABAP 多表联合查询
- 关于重写
- Linux文件属性
- 动态规划算法
- 2013年前半年总结
- android系统 按钮样式
- 多表联合查询问题
- 读取YU12文件中的Y分量内容,并一桢一桢的保存下来
- 天易33----java数组的一些基本使用
- CSS Masks
- 2013 eoe移动开发者大会,技术改变世界 会后感
- DHD刷机步骤(Rooted)
- linux nfs挂载方法
- 面试题大集合
- IE11 Enhanced Protected Mode 解决BHO与高权限进程通信问题