sql server 2000:字段:productno(nvarchar(30)),productname(nvarchar(40)),type(nvarchar(30))如何只显示字段type下的一条记录,type的值有很多是重复,只显示一条即可!谢谢!

解决方案 »

  1.   

    select productno,productname,min(type) as type from tb group by productno,productname
      

  2.   

    select * from tablename a where exists(select 1 from tablename where type=a.type and productno>a.productno)
      

  3.   


    select T.* from T
    inner join 
     (select min(productno) as productno,type from T group by type) A
    on T.productno=A.productno and T.type=A.type
      

  4.   

    declare @a table(pikd int identity(1,1),productno nvarchar(30),productname nvarchar(40),type nvarchar(30))insert @a
    select * from Yourtableselect * from Yourtable a
    inner join 
    (select max(Pkid) Pkid from @a
    group by type) b
    on a.PKID = b.PKID