列出所有部门的部门名称和部门员工人数。如果部门没有员工,人数显示为0。正确的查询语句有_________。
A: SELECT dname,COUNT(ename) AS ecount
FROM dept,emp
WHERE emp.deptno(+)=dept.deptno
GROUP BY dept.dname
B: SELECT dname,(SELECT COUNT(*) AS ecount FROM emp WHERE emp.deptno=dept.deptno)
FROM dept
C: SELECT dname,COUNT(ename) AS ecount
FROM dept LEFT JOIN emp ON emp.deptno=dept.deptno
GROUP BY dept.dname
D: SELECT dname,COUNT(*) AS ecount
FROM dept LEFT JOIN emp ON emp.deptno=dept.deptno
GROUP BY dept.dname
A: SELECT dname,COUNT(ename) AS ecount
FROM dept,emp
WHERE emp.deptno(+)=dept.deptno
GROUP BY dept.dname
B: SELECT dname,(SELECT COUNT(*) AS ecount FROM emp WHERE emp.deptno=dept.deptno)
FROM dept
C: SELECT dname,COUNT(ename) AS ecount
FROM dept LEFT JOIN emp ON emp.deptno=dept.deptno
GROUP BY dept.dname
D: SELECT dname,COUNT(*) AS ecount
FROM dept LEFT JOIN emp ON emp.deptno=dept.deptno
GROUP BY dept.dname
举一反三
- 列出所有员工的姓名、部门名称和工资。正确的SQL语句有________。 A: SELECT a.ename <br> ,(SELECT b.dname FROM dept b) AS dname <br> ,sal <br>FROM emp a B: SELECT a.ename <br> ,(SELECT b.dname FROM dept b WHERE b.deptno=a.deptno) AS dname <br> ,sal <br>FROM emp a; C: SELECT a.ename,b.dname,sal <br>FROM emp a,dept D: SELECT a.ename,b.dname,sal <br>FROM emp a,dept b <br>WHERE a.deptno=b.deptno
- 统计每个部门中人数的语句是? A: select count(id) from emp order by deptno; B: select sum(id) from emp order by deptno; C: select count(id) from emp group by deptno; D: select sum(id) from emp group by deptno;
- 智慧职教: 表结构如下:dept(deptno,dname),emp(empno,ename,job,hiredate,sal,deptno)。创建视图查询系部名称、教师姓名,职位,工资信息。
- 查询部门20的员工数量,每个月的工资总和及平均工资( ) A: SELECT sum(nvl(sal,0)),avg(nvl(sal,0)) from emp B: SELECT ename,sum(nvl(sal,0)),avg(nvl(sal,0)) from emp where deptno =20 group by deptno C: SELECT ename,count(empno),sum(nvl(sal,0)),avg(nvl(sal,0)) from emp where deptno =20 group by deptno D: SELECT count(empno),sum(nvl(sal,0)),avg(nvl(sal,0)) from emp where deptno =20 group by deptno
- 现有关系模式: EMP(empno,ename,mgr,sal,workday) 以及DEPT(deptno,dname,loc) ,以下视图中不可能更新的为________