我想查询出一个表中不重复的数据,重复的取articleid 最大的,按照articleid 的倒叙排列,我是下面的写法,结果运行出来不对。
SELECT Publicaccounts,articleid FROM article GROUP BY Publicaccounts,articleid order by articleid desc
------解决方案--------------------
select * from article as t where not exists(select 1 from article where Publicaccounts=t.Publicaccounts and articleid>t.articleid) order by articleid desc
------解决方案--------------------
试试:
select
*
from
( select *, ROW_NUMBER() over( order by AutoId,order by articleid desc ) row from article as s where 1=1 and not exists(select 1 from article where Publicaccounts=s.Publicaccounts and articleid>s.articleid) ) t
where
row between 1 and 20