解决方案 »

  1.   

    简单来写就是:
    select 月份,count(人数)
    from T_EMPLOYEE_INFORMATION
    group by 月份复杂一点的话要看表结构和数据,比如离职的人你是直接删除还是做个标识而已
      

  2.   


    这样不行吧   
     有三列  分别是  id   name   入职日期    (不考虑  离职)
                                    1   a            2014/01/01
                                   2    b            2014/02/01
                                   3    c            2014/03/01 
    查完 是      2014年(月)       人数
                             1月                         1
                              2月                        2
                                3月                      3
                               4月                      3 
    你这样 查的话 最多 也就能查出  当年 当月 入职了多少人   我查的是当前年 月以前有多少人    比如  我2014 年一年 公司 每月有公司有多少人    而不是  每月 入职多少人
      

  3.   

    你一开始就说清楚的话就不用浪费那么多时间了----------------------------------------------------------------
    -- Author  :DBA_HuangZJ(發糞塗牆)
    -- Date    :2014-09-04 16:53:01
    -- Version:
    --      Microsoft SQL Server 2012 - 11.0.5058.0 (X64) 
    -- May 14 2014 18:34:29 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
    --
    ----------------------------------------------------------------
    --> 测试数据:[huang]
    if object_id('[huang]') is not null drop table [huang]
    go 
    create table [huang]([id] int,[name] varchar(1),[入职日期] datetime)
    insert [huang]
    select 1,'a','2014/01/01' union all
    select 2,'b','2014/02/01' union all
    select 3,'c','2014/03/01'
    --------------开始查询--------------------------select DATEPART(MONTH,[入职日期])[月份],(SELECT COUNT(name) FROM huang b WHERE b.入职日期<=a.入职日期)[人数]
    from [huang] a
    ----------------结果----------------------------
    /* 
    月份          人数
    ----------- -----------
    1           1
    2           2
    3           3
    */
      

  4.   

    这个如果每月超过一个人就会出问题,而且每个人入职时间不一定是每月一号呀,试一下下面这个
    insert into huang values (1,'a','2014-01-01 00:00:00.000')
    insert into huang values (2,'b','2014-02-01 00:00:00.000')
    insert into huang values (3,'c','2014-03-01 00:00:00.000')
    insert into huang values (4,'c','2014-01-01 00:00:00.000')
    insert into huang values (5,'d','2014-04-01 00:00:00.000')
    insert into huang values (6,'e','2014-04-20 00:00:00.000')
    with temp as
    (select datepart(yy,[入职日期]) as [year],datepart(m,[入职日期]) as [month]
    ,count(*) as count1
    from [huang] group by datepart(yy,[入职日期]),datepart(m,[入职日期]))
    --select * from temp
    select [year],[month],
    (select sum(count1) from temp b where (a.[year]>b.[year]) or (a.[year]=b.[year])
     and a.[month]>=b.[month])
    from temp a