当前位置: 代码迷 >> Sql Server >> sql数据重复查询有关问题
  详细解决方案

sql数据重复查询有关问题

热度:60   发布时间:2016-04-24 10:28:46.0
sql数据重复查询问题
我想查询出一个表中不重复的数据,重复的取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
 
  相关解决方案