select wname,cid,checkdate,min(isnull(detail,''))+' '+max(isnull(detail,'')) as  detail from 表a group by wname,cid,checkdate

解决方案 »

  1.   

    表a如下:
    wname    cid       checkdate           detail
    ------------------------------------------------
    小国 12345678 NULL            NULL
    小李 3214280 2006-01-04 22:11:25
    小李 3214280 2006-01-04 22:11:39
    小张 3240893 2006-01-04 22:11:26
    小张 3240893 2006-01-04 22:11:40
    刘工 6586244 2006-01-04 22:11:25
    刘工 6586244 2006-01-05 22:11:39结果是
    刘工 6586244 2006-01-04 22:11:25 22:11:39
    特权卡 5974028 NULL  
    特权卡 5983148 NULL  
    小国 12345678 NULL  
    小李 3214280 2006-01-04 22:11:25 22:11:39
    小张 3240893 2006-01-04 22:11:26 22:11:26
    小张 3240893 2006-01-05 22:11:40 22:11:40
    22:11:40 22:11:40重复了。
      

  2.   

    --加个聚合函数
    select wname,cid,checkdate=max(checkdate),min(isnull(detail,''))+' '+max(isnull(detail,'')) as  detail
     from @t group by wname,cid