MySql

数据库数据排序完后,只显示相同id的前三条数据

2017-03-04  本文已影响2人  一名鼻炎患者
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
上一篇下一篇

猜你喜欢

热点阅读