mysql 分组topN
来源:互联网 发布:mysql.host不存在 编辑:程序博客网 时间:2024/06/05 00:39
比较快的实现:
select a.* from his_tender_count a join (select trans_month,max(create_time)as create_time from his_tender_count group by trans_month) b on a.trans_month=b.trans_month and a.create_time=b.create_time where a.trans_month> DATE_FORMAT(NOW(),'%Y');
| id | trans_amount | trans_count | trans_month | count_date | create_time |
+------+---------------+-------------+-------------+---------------------+---------------------+
| 2 | 17.3890614901 | 313 | 2017-02-01 | 2017-07-26 16:19:29 | 2017-07-26 16:19:29 |
| 3 | 24.1876869497 | 290 | 2017-06-01 | 2017-07-26 16:19:29 | 2017-07-26 16:19:29 |
阅读全文