我有个表,起结构如下
cProc_ID     cSht_ID    PushDate                cMod_ID
333           104      2006-08-21 14:54:41       1
334           104      2006-08-21 14:58:18        36
464           104       2006-09-18 10:35         34465           105      2006-09-19 15:02:25        34
336           105      2009-09-18 10:45:10        1
338           105      2009-08-20  11:56:50       36我想要的结果是,按照cSht_ID分组,然后取得每组中 PushDate最大的那条记录,即最终要的是
464           104       2006-09-18 10:35         34
465           105      2006-09-19 15:02:25        34
这两条记录,sql该如何写呢?多谢了

解决方案 »

  1.   

    SELECT * FROM TB T WHERE NOT EXISTS
    (SELECT 1 FROM TB WHERE T.cSht_ID =cSht_ID  AND cProc_ID>T.cProc_ID)
      

  2.   

    select * from tb where PushDate=(select max(PushDate) from tb where cSht_ID=t.cSht_ID)
      

  3.   


    select * from Tb A
    join(
        select cSht_ID,max(PushDate) as PushDate from Tb group by cSht_ID
        )as b
    on A.cSht_ID=b.cSht_ID and A.PushDate=b.PushDate
      

  4.   

    select  *  from  表  where exists (selec cSht_ID, max(PushDate) from 表 group by cSht_ID)
      

  5.   

    select * from tb t where PushDate=(select max(PushDate) from tb where cSht_ID=t.cSht_ID)
      

  6.   

    SELECT * FROM TB T WHERE NOT EXISTS
    (SELECT 1 FROM TB WHERE T.cSht_ID =cSht_ID  AND PushDate>T.PushDate)
      

  7.   

    select * from [www.gzqc17.net] where cMod_ID=34