select  to_char(a.fd_create_date, 'yyyy-MM-dd HH:MM:SS') as p_date,
             c.fd_number,
              b.fd_name,
              c.doc_subject
  from sys_wf_audit_note a, km_review_main c,sys_org_element b
 where  a.fd_process_id = c.fd_id
   and           a.fd_handler_id = b.fd_id
   and a.fd_process_id   in
   (select fd_id
          from km_review_main
         where fd_template_id = '136f1a535c4918dd12dc8554cf3bb9f0')
     order by c.doc_subject
查询结果:
     C:\Users\zikang_li\Desktop如何只取每组的日期最新的一条记录?
求高手指导

解决方案 »

  1.   

    没看明白你是则么分组的,
    下面这个应该可以满足吧
    使用row_number()over(partition by 分组字段 order by 时间 desc) num,
    取num=1就可以了
      

  2.   

    select max(to_char(a.fd_create_date, 'yyyyMMdd HHMMSS')),to_char(a.fd_create_date, 'yyyy-MM-dd HH:MM:SS') as p_date,
      c.fd_number,
      b.fd_name,
      c.doc_subject
      from sys_wf_audit_note a, km_review_main c,sys_org_element b
     where a.fd_process_id = c.fd_id
      and a.fd_handler_id = b.fd_id
      and a.fd_process_id in
      (select fd_id
      from km_review_main
      where fd_template_id = '136f1a535c4918dd12dc8554cf3bb9f0')
      order by c.doc_subject这样行不行...
      

  3.   


    比如表t1 有2个字段 一个c1 一个c2(时间)
    select c1,max(c2) c2 
    from t1
    group by c1