易截截图软件、单文件、免安装、纯绿色、仅160KB

谁帮忙写个SQL语句

谁帮忙写个SQL语句
凌建锐 26分钟前 
两张表关联 部门 员工 
要求查出员工人数小于三的 所有部门的编号和名称
select count(empno),d.dname from emp e,dept d where e.deptno=d.deptno group by d.dname
这是查出每个部门的人数,然后就不会写呢。哪位朋友帮一下忙!谢谢了 !
多看书

1楼 好有幽默感啊。你多看看书吧,学会了再来回答。

SQL code:
SELECT d.deptno, d.dname
from dept d,
(SELECT d.deptno
from emp e, dept d
WHERE d.deptno = e.deptno(+)
GROUP BY d.deptno
HAVING COUNT(1) < 3) a
WHERE d.deptno = a.deptno




引用
SQL code
select d.deptno,d.dname
from dept d,(
select deptno,count(*) count_emp
from emp
group by deptno
)a
where count_emp<3 and
d.deptno=a.deptno;

这个比较保险一点,能把全部查出来

4楼 我想问一下 count_emp<3 这个是什么意思? 可以告诉我吗?

--部门中人数总和小于3


哦,我看到了,那是个别名。谢谢你啦。


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

求一sql语句 - MS-SQL Server / 疑难问题

现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......

一个pl/sql问题 - Oracle / 开发

我是在toad中输入下段sql
  declare
  TYPE test_rec IS record(
  code varchar(10),
  name varchar(30)
  );
  v_book test_rec;
    ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号