有一个表TABLE,他的字段和数据如下:
      CD             DATE
     001         2006/02/02
     001         2006/02/05
     002         2006/05/02
     002         2006/05/05查询得到的结果为
      CD             DATE
     001              0
     001         2006/02/05
     002              0
     002         2006/05/05就是把日期最小的写为0,这个SQL如何写???

解决方案 »

  1.   

    update t set DATE=0 from [TABLE] t where exists(select 1 from [TABLE] where CD=t.CD and DATE>t.DATE)
      

  2.   

    晕啊,老大我要的是SELECT语句,不是UPDATE
      

  3.   

    create table t(cd varchar(10),date varchar(10))insert into t(cd,date)
    select '001','2006/02/02' union all
    select '001','2006/02/05' union all
    select '002','2006/05/02' union all
    select '002','2006/05/05'select cd,case date when (select  min(date) from t where t.cd=t1.cd) then '0' else date end date from t t1