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

Fs_2011 2011-12-05 01:38:20
数据表P 中有字段Name Price Time Describ Id
表中有记录Name Price Time Describ 全部相同,只Id不同,
想筛选出其中一条记录,无论是哪一条,只要查询结果不重复就行
...全文
158 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
JS 2011-12-07
  • 打赏
  • 举报
回复
没时间一直上外网在守在这里解决问题和借鉴高人的方法 悲催啊 fredrickhu和qianjin036a、ssp2009都是大拿啊 我进的每个帖子几乎都有他们 天天盘踞在这里为人排忧解难 真是热心肠的好人啊
只记今朝笑 2011-12-06
  • 打赏
  • 举报
回复
好简单的问题啊!可能是没明白你的意思吧。
方法1:
SELECT Top 1 Name,Price,Time,Describ FROM p Order By id DESC
方法2:
SELECT Distinct Name,Price,Time,Describ FROM p
q465897859 2011-12-06
  • 打赏
  • 举报
回复
+1[Quote=引用 6 楼 fredrickhu 的回复:]
SQL code

select
*
from
(select px=row_number()over(partition by Name ,Price ,Time ,Describ order by getdate()),* from tb)t
where
px=1
[/Quote]
勿勿 2011-12-06
  • 打赏
  • 举报
回复
distinct
rjthinking 2011-12-05
  • 打赏
  • 举报
回复
select * from table where id in (select max(id) from table group by [Name], [Price], [Time] ,[Describ])
--小F-- 2011-12-05
  • 打赏
  • 举报
回复
select
*
from
(select px=row_number()over(partition by Name ,Price ,Time ,Describ order by getdate()),* from tb)t
where
px=1
-晴天 2011-12-05
  • 打赏
  • 举报
回复
select distinct Name, Price, Time, Describ from P
Fs_2011 2011-12-05
  • 打赏
  • 举报
回复
我的id是uniqueidentifier,不能用max和min函数的
pengxuan 2011-12-05
  • 打赏
  • 举报
回复

--方法一:
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)

--小F-- 2011-12-05
  • 打赏
  • 举报
回复
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)
快溜 2011-12-05
  • 打赏
  • 举报
回复
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 )

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧