在员工资料中有这样的字段:入本单位的日期、合同到期的日期等,(例如员工的数据很多)
 请问:通过如何的查询能够查到这样的表出来:
           字段1                     字段2
       本月合同到期的人数             10人
       今天合同到期的人数              2人请求大虾们这个语句怎么写呀?

解决方案 »

  1.   

    select '本月合同到期的人数' as field1 ,count(*) as field2 from table where .......
    union
    select '今天合同到期的人数' as field1 ,count(*) as field2 from table where .......
    '
      

  2.   

    yiyueye,你误解我的意思了。
      要先判断后才select 的,但我不会呀,
      

  3.   

    ....入本单位的日期、合同到期的日期等
             字段1                     字段2
           本月合同到期的人数             10人
           今天合同到期的人数              2人
    ========================select f1='本月合同到期的人数', f2=cast(count(*) as varchar(10))+'人' from table where Month(合同到期日期)=Month(GetDate())
    union all
    select f1='今天合同到期的人数', f2=cast(count(*) as varchar(10))+'人' from table where 合同到期日期=GetDate()