我想根据一个打卡系统得出当月所有人打卡的明细表:
表名:punch_card_record  
字段:user_id,user_name,record_date(打卡日期 日期类型),onduty_time(上班时间 时间类型),
  offduty_time(下班时间 时间类型)
我现在完成的语句只能实现某一天的查询下:
        X年X月X日                                                                  
张三    √    △   
李四    √    △   
王五    √    △   
我需要得到的表格是这样:
        X年X月X日    X年X月X+1日张三    √    △      √    √
李四    √    △      √    √
王五    √    △      √    △我写的语句如下:
select distinct a.user_id,a.user_name,
((select  case when to_char(b.onduty_time,'hh24:mi')<='09:00' then '√'
 else to_char(b.onduty_time,'hh24:mi') end  from punch_card_record b where b.user_id=a.user_id 
 and b.record_date = to_date('2009-03-01','yyyy-mm-dd' ))||','||
(select  case when b.offduty_time is null then '×'
 when to_char(b.offduty_time,'hh24:mi')>='17:20' then '√' 
 when to_char(b.offduty_time,'hh24:mi')<='17:20' then to_char(b.offduty_time,'hh24:mi') 
 end  from punch_card_record b where b.user_id=a.user_id 
 and b.record_date = to_date('2009-03-01','yyyy-mm-dd' )) ) "1"
from punch_card_record a

解决方案 »

  1.   

    建议楼主再用一些语言描述吧?
      

  2.   

    晕,不好意思,可能我的描述不够清楚。
    打卡系统只纪录每个人每一天的上班下班时间
    每个人每一天是一条数据。
    我想统计成一个明细表 能清楚的知道,这个月每一天 所有人的打卡情况 就象上面的例子中那样。
      

  3.   

    用通用的行转列过程或者函数处理