这是我的代码:
SELECT dname,loc,avg(sal)
FROM dept,emp
GROUP BY loc;
我想写一个查询来显示部门名称,位置,员工人数以及该部门所有员工的平均工资。标记列dname,loc,员工数量和Avgsalary。
数据是:
DNAME LOC Number of People Salary
-------------- ------------- ---------------- ----------
SALES CHICAGO 6 1566.67
RESEARCH DALLAS 5 2175
ACCOUNTING NEW YORK 3 2916.67
答案 0 :(得分:1)
- 不需要SUM(1)使用COUNT(e.deptno)作为人数 -
select d.dname as DNAME, d.loc as LOC, count(e.deptno)as "Number of people", round(avg(e.sal),2) as "Salary" from dept d, emp e where d.deptno = e.deptno group by d.dname, d.loc, e.deptno;
答案 1 :(得分:0)
你只是错过了选择列表中的SUM(1),而你的小组可能错误地提出了这个问题:
select dname as DNAME, loc as LOC, SUM(1) as Number_of_People, avg(sal) as AvgSalary from dept,emp group by dname, loc;