+ -
当前位置:首页 → 问答吧 → sql语句查询筛选重复值问题

sql语句查询筛选重复值问题

时间:2011-12-05

来源:互联网

数据表P 中有字段Name Price Time Describ Id
表中有记录Name Price Time Describ 全部相同,只Id不同,
想筛选出其中一条记录,无论是哪一条,只要查询结果不重复就行

作者: Fs_2011   发布时间: 2011-12-05

SQL code
select * from P t
 where not exists(select 1 from P where Name=t.Name and Price=t.Price 
                     and [Time]=t.[Time] and Describ=t.Describ and id<t.Describ )

作者: ssp2009   发布时间: 2011-12-05

SQL code
select
  *
from
  p t
where
  id=(select max(id) from p where  Name=t.Name and Price=t.Price and [Time]=t.[Time] and Describ=t.Describ)

作者: fredrickhu   发布时间: 2011-12-05

SQL code

--方法一:
select * from tb a where id=(select max(id) from tb where Name=a.Name and price=a.price and Time=a.time and Describ=a.Describ)
--方法二
select * fromt b a where not exists(select 1 from tb where Name=a.Name and price=a.price and Time=a.time and Describ=a.Describ and id>a.id)


作者: pengxuan   发布时间: 2011-12-05

我的id是uniqueidentifier,不能用max和min函数的

作者: Fs_2011   发布时间: 2011-12-05

SQL code
select distinct Name, Price, Time, Describ from P

作者: qianjin036a   发布时间: 2011-12-05

SQL code
select
  *
from
  (select px=row_number()over(partition by Name ,Price ,Time ,Describ order by getdate()),* from tb)t
where
  px=1

作者: fredrickhu   发布时间: 2011-12-05

热门下载

更多