目测一楼的 sql 不行 select user group by user 是可以,其它的字段必须是 aggregate function. select logintime 是不行的。另外 order 需要在 group 后面
1.分两次查询 SELECT user, count(*) AS cnt FROM userlog GROUP BY user ORDER BY cnt; SELECT logintime FROM userlog WHERE user=? ORDER BY logintime;
2.利用 GROUP_CONCAT ( mysql 用得少,未实测,不保证书写正确) SELECT user, count(*) AS cnt, GROUP_CONCAT(logintime SEPARATOR '\n' ORDER BY logintime) AS logintimes FROM userlog GROUP BY user ORDER BY cnt;