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 ------解决方案--------------------