1.以user_q倒序显示前三条记录
$sql='select * from daily_report as main where (
select count(1) FROM daily_report AS sub where main.server_id = sub.server_id and main.user_q< sub.active_user_q ) < 3 order by user_q DESC;
$Report=$Model->query($sql);
Paste_Image.png
2.每个mach_id 只显示两条数据
SELECT *
FROM tbl_mt_log a
WHERE 2 > ( SELECT count(*)
FROM tbl_mt_log
WHERE mach_id = a.mach_id
AND mt > a.mt)
ORDER BY a.mach_id, a.mt DESC
网友评论