重复过滤相关的问题
例
select distinct 字段1 from a
select top 1 * from a where 字段2=字段1 order by 时间字段3 desc
大家帮忙看看,能否把2条语句合为1条语句
[解决办法]
要达到什么目的
distinct 是去重复的.
top 1 是取 order by 时间字段3 desc 第一个的.
你想要达到什么样的目的呢.
[解决办法]
select top 1 *
from a
where 字段1 in (select distinct 字段1 from a)
order by 时间字段3 desc
[解决办法]
select top 1 * from a where 字段2=字段1 and 字段1 in(select distinct 字段1 from a) order by 时间字段3 desc
[解决办法]
我知道意思了,分组后求第一
select A.字段1,A.时间字段3
from a as A
where no exists (select 1 from a as AA where A.字段1 = AA.字段1 and A.时间字段3>AA.时间字段3)
[解决办法]
select distinct 字段1 into #a from a
while exists(select 1 from #a)
begin
select top 1 * from a where 字段2=字段1 order by 时间字段3 desc
delete top 1 from #a
end
[解决办法]
那兄弟,你上示例数据和预期查询结果数据示例 吧
不然真不知道,你想要哪方便的。