部门表 dept                              用户表 user
id           name                        id       deptID      name      state    born_date
1            开发                        1         1          张四      在职     1976-02-01
2            市场                        2         1          李四      在职     1983-03-01
3            售后                        3         2          王伍      在职     1985-08-02
                                         4         3          彭六      离岗     1990-04-11
                                         5         3          陈七      在职     1982-05-23
1、结果如下:
          部门名称              人数
          开发                  2
          市场                  1
          售后                  12、出生在1982年--1987年的员工。

解决方案 »

  1.   

    select b.name,count(1) as 人数 
    from [user] a left join [dept] b on a.deptID=b.deptID
    where a.state='在职' group by b.name
      

  2.   

    select * from [user] where year(born_date) between 1982 and 1987
      

  3.   

    怎么只有1个DEPTID??是怎么关联的?
      

  4.   

    --第2题
    select * from [user] where year(born_date) between 1982 and 1987
      

  5.   


    -- 1
    SELECT a.id,a.name,COUNT(1) as 人数 FROM 部门表  a join 用户表 b on a.id=b.deptid GROUP BY a.id,a.name--2
    select * from 用户表 where YEAR(born_date) between 1982 and 1987