select startdate ,     enddate ,     A_EId ,
  sum(case A_state when '迟到' then 1 else 0 end) [迟到],
  sum(case A_state when '早退' then 1 else 0 end) [早退],
  sum(case A_state when '请假' then 1 else 0 end) [请假],
  sum(case A_state when '旷工' then 1 else 0 end) [旷工]
from Attendances
group by startdate ,     enddate ,     A_EId 

解决方案 »

  1.   

    select startdate = @startdate ,  enddate = @enddate,     A_EId ,
      sum(case A_state when '迟到' then 1 else 0 end) [迟到],
      sum(case A_state when '早退' then 1 else 0 end) [早退],
      sum(case A_state when '请假' then 1 else 0 end) [请假],
      sum(case A_state when '旷工' then 1 else 0 end) [旷工]
    from Attendances
    where A_date between @startdate and @enddate
    group by A_EId 
    1楼我回复错了,不好意思.
      

  2.   

    try:select 
        @startdate as startdate,
        @enddate   as enddate  ,
        A_EId,
        sum(case A_state when '迟到' then 1 else 0 end) as 迟到,
        sum(case A_state when '早退' then 1 else 0 end) as 早退,
        sum(case A_state when '请假' then 1 else 0 end) as 请假,
        sum(case A_state when '旷工' then 1 else 0 end) as 旷工
    from
        Attendances
    where
        A_date between @startdate and @enddate
    group by
        A_EId
      

  3.   


        A_EId
    dDeclare @start datetime
    declare @end datetime
    select 
        @start as startdate,
        @end   as enddate  ,
        A_EId,
        sum(case A_state when '迟到' then 1 else 0 end) as 迟到,
        sum(case A_state when '早退' then 1 else 0 end) as 早退,
        sum(case A_state when '请假' then 1 else 0 end) as 请假,
        sum(case A_state when '旷工' then 1 else 0 end) as 旷工
    from
        Attendances
    where
        A_date between @start and @end
    group by
    没有出错,但是没有一条记录的哦,??????