各位SQL高手,大侠!
    我要把下面的数据:
 --------------------------------------------------------------------------------------
code      kh_id   ht_name      ht_jiafang     ht_amount   ss_amount    yuer         ss_date
  
H00001  K0001 D销售合同   厦门ss有限公司 65000|元     6800        50000|元 2010-01-07 
H00001  K0001 D销售合同   厦门ss有限公司  65000|元     2500       50000|元 2010-01-06 
H00001  K0001 D销售合同   厦门ss有限公司 65000|元     4000       51700|元 2010-01-06 
H00002  K0001 bbb合同   大连bbb公司 1300|元      120       1180|元 2009-12-03 
H00002  K0001 bbb合同   大连bbb公司     1300|元      920        380|元     2009-12-01 
H00002  K0001 bbb合同   大连bbb公司 1300|元      750        550|元 2009-11-30  通过sql,得到下面的结果:即不同的记录,只显示最新时间的一条,
 -------------------------------------------------------------------------------------
   code      kh_id   ht_name      ht_jiafang      ht_amount   ss_amount    yuer         ss_date
  
   H00001     K0001    D销售合同   厦门ss有限公司   65000|元 6800   50000|元       2010-01-07 
   H00002     K0001   bbb合同     大连bbb公司     1300|元  120   1180|元      2009-12-03  ------------------------------------------------------------------------------------- 各位高手,帮帮忙。急!!! 在线等!

解决方案 »

  1.   

    select t.* from tb t where ss_date =(select max(ss_date ) from tb where code = t.code) order by t.codeselect t.* from tb t where not exists (select 1 from tb where code = t.code and ss_date > t.ss_date ) order by t.code
      

  2.   


    select * from 表名 a
    where not exists(select 1 from 表名 where code=a.code and ss_date >a.ss_date )
      

  3.   

    select * from [tb] t
    where not exists (select 1 from [tb] where ss_date>t.ss_date and code=t.code )
      

  4.   

    谢谢,dawugui(爱新觉罗.毓华)大侠! 最快的,有用,给你多分,其他的大侠给小分吧。不够意思,分数不够多。抱歉了!
      

  5.   

    create table tb(
    code varchar(20),
    kh_id varchar(20), 
    ht_name varchar(20), 
    ht_jiafang varchar(20), 
    ht_amount varchar(20), 
    ss_amount int, 
    yuer varchar(20), 
    ss_date datetime)
    go
    insert into tb values('H00001', 'K0001', 'D销售合同' , '厦门ss有限公司' , '65000|元' , 6800 , '50000|元', '2010-01-07') 
    insert into tb values('H00001', 'K0001', 'D销售合同' , '厦门ss有限公司' , '65000|元' , 2500 , '50000|元', '2010-01-06') 
    insert into tb values('H00001', 'K0001', 'D销售合同' , '厦门ss有限公司' , '65000|元' , 4000 , '51700|元', '2010-01-06') 
    insert into tb values('H00002', 'K0001', 'bbb合同' , '大连bbb公司' , '1300|元' , 120 , '1180|元' , '2009-12-03') 
    insert into tb values('H00002', 'K0001', 'bbb合同' , '大连bbb公司' , '1300|元' , 920 , '380|元' ,'2009-12-01') 
    insert into tb values('H00002', 'K0001', 'bbb合同' , '大连bbb公司' , '1300|元' , 750 , '550|元' ,'2009-11-30')
    goselect t.* from tb t where ss_date =(select max(ss_date ) from tb where code = t.code) order by t.codeselect t.* from tb t where not exists (select 1 from tb where code = t.code and ss_date > t.ss_date ) order by t.code
    drop table tb /*
    code                 kh_id                ht_name              ht_jiafang           ht_amount            ss_amount   yuer                 ss_date                                                
    -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- ------------------------------------------------------ 
    H00001               K0001                D销售合同                厦门ss有限公司             65000|元              6800        50000|元              2010-01-07 00:00:00.000
    H00002               K0001                bbb合同                大连bbb公司              1300|元               120         1180|元               2009-12-03 00:00:00.000(所影响的行数为 2 行)code                 kh_id                ht_name              ht_jiafang           ht_amount            ss_amount   yuer                 ss_date                                                
    -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- ------------------------------------------------------ 
    H00001               K0001                D销售合同                厦门ss有限公司             65000|元              6800        50000|元              2010-01-07 00:00:00.000
    H00002               K0001                bbb合同                大连bbb公司              1300|元               120         1180|元               2009-12-03 00:00:00.000(所影响的行数为 2 行)*/
      

  6.   

    select t.* from tb t where ss_date in (select max(ss_date ) from tb where code = t.code) order by t.code