题目描述这是SQL今日一题的第18篇文章
统计各个部门的工资记录数,给出部门编码dept_no、部门名称dept_name以及部门在salaries表里面有多少条记录sum
这题用到salaries表、dept_emp表和departments表



selectdp.dept_no,dp.dept_name,count(s.salary)assum
fromdept_empde,departmentsdp,salariess
wherede.dept_no=dp.dept_no
andde.emp_no=s.emp_no
groupbydp.dept_no,dp.dept_name
1、用where将3个表连接在一起,dept_emp表和departments表用dept_no连接,dept_emp表和salaries表用emp_no连接
2、题目中说在salaries表里面有多少条记录sum,虽然有sum出现,但用的是count计数,只是将这个字段命名为sum,这一点需要注意。同时因为使用了count聚合函数,要用group by进行分组。
3、where连接的效果和inner join是一样的。
selectdp.dept_no,dp.dept_name,count(s.salary)assum
fromdept_empde
innerjoindepartmentsdponde.dept_no=dp.dept_no
innerjoinsalariessonde.emp_no=s.emp_no
groupbydp.dept_no,dp.dept_name
结果都是如下图所示

3表连接
where连接,确定好公共字段
子查询先连两个再和第三个连
猜你喜欢:
数据分析应关注AARRR模型的哪些指标
泰坦尼克号数据分析
深入浅出数据分析
@ 作者:可乐
@ 公众号/知乎专栏/头条/简书:可乐的数据分析之路
@加个人微信:data_cola,备注:进群,拉你入 可乐的数据分析群 和各行各业的小伙伴交流探讨数据分析相关内容


以上就是关于SQL今日一题(18):3表连接什么叫模式全部的内容,关注我们,带您了解更多相关内容。