select a.Id,a.Type,a.Title,a.ShowTime,a.UserName,a.ExternalLinks,a.Cover,a.PlainText, a.IsState,count(*) as num
from (select * from news where IsState=1 and IsDeleted=0) as a
inner join (select * from news where IsState=1 and IsDeleted=0) as b ON a.Type=b.Type
where b.id>=a.id
and a.Type in (0,2) group by a.id having num<=5 order by a.type,num;
同一个表中查询每个分类的前5条数据
最新推荐文章于 2024-07-04 16:31:38 发布