日期:2014-05-19  浏览次数:20848 次

如果只显示某个分类下面的一条记录
sql   server   2000:

字段:productno(nvarchar(30)),productname(nvarchar(40)),type(nvarchar(30))

如何只显示字段type下的一条记录,type的值有很多是重复,只显示一条即可!

谢谢!

------解决方案--------------------
select productno,productname,min(type) as type from tb group by productno,productname
------解决方案--------------------
select * from tablename a where exists(select 1 from tablename where type=a.type and productno> a.productno)
------解决方案--------------------

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
------解决方案--------------------
declare @a table(pikd int identity(1,1),productno nvarchar(30),productname nvarchar(40),type nvarchar(30))

insert @a
select * from Yourtable

select * from Yourtable a
inner join
(select max(Pkid) Pkid from @a
group by type) b
on a.PKID = b.PKID