资讯课  6300  张三  8:00 12:00  6:00   2010年10月20号打卡记录
资讯课  6300  李四  8:00  12:00         2010年10月20号打卡记录
财务  5300     王五 8:00   12:00         2010年 10月20号打卡
现在显示结果
资讯课  6300  早上打卡人数2 中午 2 晚上 1  2010年10月20号
财务    5300   早上打卡人数1 中午1 晚上    2010年10月20号

解决方案 »

  1.   

    我写的会比较麻烦,用case then...when的语法写,也就是在sql语句中进行判断+分组,我也来等大牛的回答
      

  2.   

    你这个是一个表吗?有晚上打卡时间,早上打卡时间,中午打卡时间三个列?如果没打卡就为null对吗?
    你试下:
    select 课室,ID,'早上打卡人数'+str(sum(case when 早上打卡 is null then 0 else 1 end)),'中午'+str(sum(case when 中午打卡 is null then 0 else 1 end)),'晚上'+str(sum(case when 晚上打卡 is null then 0 else 1 end)),日期
    From Table
    Group By 课室,ID,日期
      

  3.   


    select 部门,[id], count(早上),count(中午),count(晚上) from table1 group by 打卡日期,部门,[id]