大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说sqlserver分组排序取最大一条_sql组内排序,希望您对编程的造诣更进一步.
表结构:
方法1:
select a.* from Table_Test as a where 3 >
(select count(*) from Table_Test where Brand_Id = a.Brand_Id and AddTime > a.AddTime )
order by a.Brand_Id,a.AddTime desc
方法2:
select * from
(select *,ROW_NUMBER() over( partition by Brand_Id order by AddTime desc ) as a from Table_Test) as c
where a<4
运行sql后对应数据:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8747.html