尽可能简单描述select * from tableA(出勤记录表)得到结果
p_code play_date
0001   201010821
0001   201010824
0001   201010827
0002   201010901
0002   201011021
0002   201011124
0002   201010502
0003   201010705
0004   201010803
0005   201011107
0006   201011209
.....
p_code是员工号, play_date是出勤的日期我现在想得到如下统计结果(就是统计每个员工出勤了几天) p_code,date_num
0001   3天
0002   4天
0003   1天

请问,sql该如何写呢?求助各位~

解决方案 »

  1.   

    select p_code, to_char(count(*)) || '天' 出勤天数 from tableA
    group by p_code
      

  2.   

    select p_code,count(*) date_num
      from tableA
     group by p_code
    ;
      

  3.   


    select p_code,count(play_date)||'天数'  date_num
    from tb
    group by p_code
      

  4.   

    非常感谢123楼的回答,实在是忘记了group by的用法  至于4楼也感谢,我描述的是通过简化处理的 之前的需求都已经理清楚 tableA也是个庞大的查询合集