时间:2021-07-01 10:21:17 帮助过:13人阅读
你SQL取出来在php那端每个值取3个不就结了?
拍完序之后仅获取前三条的话可以用limit0,3;
select a.* from imginfo a where 3 > (select count(*) from imginfo where fid = a.fid and id > a.id and fid in(3,5,9)) and fid in(3,5,9) order by a.fid,a.id
SQL语句如下:
select a.* from imginfo a where 3 > (select count(*) from imginfo where fid = a.fid and id > a.id and fid in(3,5,9)) and fid in(3,5,9) order by a.fid,a.id
如果只是按ID降序,排序改下就好
select a.* from imginfo a where 3 > (select count(*) from imginfo where fid = a.fid and id > a.id and fid in(3,5,9)) and fid in(3,5,9) order by a.id desc
可以这样的哦,学习了。
学习了!谢谢版主。
select a.* from imginfo a where 3 > (select count(*) from imginfo where fid = a.fid and id > a.id and fid in(3,5,9)) and fid in(3,5,9) order by a.fid,a.id