SELECT DATE_FORMAT( start_time, '%Y-%m-%d' ) AS days, count( * ), city_id AS city_id FROM orders WHERE start_time BETWEEN '2018-11-01' AND '2018-11-10' GROUP BY days, city_id ORDER BY days DESC, city_id DESC
因为日期是datetime类型的字段,要精确到每一天,也就是只需要Y-m-d就行了。所以,就需要使用mysql的 date_format 函数将日期转换下,并根据其进行分组查询。
另外排序的语法也要注意了,多个字段排序是要字段间使用‘,’间隔,否则无效或者报错。