SQL语句,一个时间字段sendtime,
我现在只能做好日、dep的排序:
是select.... order by to_date(sendtime),dep asc;现在想先按日排序,在同一日里按照部门dep分组排序,同一个部门多条数据再按照小时分钟秒的顺序排序显示,如何做?
(我这样写不正确:select.... order by to_date(sendtime),to_time(sendtime),dep asc;)

解决方案 »

  1.   

    if senddate is date select **
      from **
     where **
    order by trunc(senddate,'DD'),dept,to_char(senddate,'hh24:mis:ss')
      

  2.   

    order by trunc(sendtime,'DD'),dep,sendtime asc;
      

  3.   

    order by extract(day from to_date(senddate)),dept,to_char(senddate,'hh24:mis:ss')
      

  4.   

    楼主的sendtime应该是char或varchar2类型的吧而后面回复的都是按照date类型来处理的如果真的是char或varchar2类型的, 应该有严格的日期格式, 可以考虑直接用substr截取sendtime部分信息作为排序字段
      

  5.   

    不知道你sendtime的数据类型.如果你的sendtime本来存储是就是按照yyyymmddHH24MISS的格式来存的话
    order by trunc(sendtime,'yyyymmdd'),dep,sendtime;
      

  6.   

    借貴地問個問題,為甚麼用query查詢視圖後,返回記祿集為-1,將view 換成table,卻一切正常.