我有一个表,结构如下,
[ID] 
        [work_id]  
[state],状态
[APPROVER_ID]  
[APPROVAL_STATUS] 
        [APPROVAL_date]审批日期
想请教各位一个存储过程,每个状态有可能审批多次,找出每个状态审批日期最进的审批信息,而且有的状态还没有审批信息,也得找出来例如每个work_id为1的下有三个状态:甲 乙 丙,然后库里有两个状态的审批信息,而且甲和乙都有多次审批记录,要找到如下信息:工作    状态    审批人   审批日期
1      甲       aaa    9999-2-22
1       乙      sss   2222-22-11
1      丙       空      空

解决方案 »

  1.   

    select * from tb t
    where not exists(select 1 from tb where work_id = t.worl_id and state = t.state and APPROVAL_DATE < t.APPROVAL_DATE)
      

  2.   


    select * from tb t where not exists
    (select 1 from tb where work_id = t.work_id and state = t.state and APPROVAL_DATE < t.APPROVAL_DATE)
      

  3.   

    select * from tb t where (select count(*) from tb where work_id = t.work_id and state = t.state and APPROVAL_DATE < t.APPROVAL_DATE )=0
      

  4.   

    条件写反了吧
    应该是这样的吧SQL codeselect * from tb t
    where not exists(select 1 from tb where work_id = t.worl_id and state = t.state and APPROVAL_DATE > t.APPROVAL_DATE)
      

  5.   

    SQL codeselect * from tb t
    where not exists(select 1 from tb where work_id = t.worl_id and state = t.state and APPROVAL_DATE > t.APPROVAL_DATE)