废话少数直接上需求和解决方案
需求:分组查询指定条数
这是我的表
表名news,查询class_id为1和2的数据各三条
这是sql:
select n1.* from news n1
where n1.`class_id` in (1,2)
group by n1.`class_id`,n1.id having (select count(n2.id) from news n2 where n2.class_id=n1.class_id and n2.id>=n1.id)<=3 order by n1.class_id desc
标签:id,条数,分组,mysql,n1,n2,news,class From: https://www.cnblogs.com/xiaoyuanhk/p/16996575.html