默认情况下,GROUP BY
子句提取的数据按升序排序.如何将其更改为降序.
您应该在SQL上使用派生表.例如,如果您想要获取您尝试使用的特定活动的最新行:
select * from activities group by id_customer order by creation_date
但它不起作用.尝试改为:
SELECT * FROM ( select * from activities order by creation_date desc ) sorted_list GROUP BY id_customer
添加DESC
到该GROUP BY
子句,例如:
GROUP BY myDate DESC
正如MySQL文档所说,
SELECT * FROM foo GROUP BY bar
相当于
SELECT * FROM foo GROUP BY bar ORDER BY bar
默认行为无法更改,但您可以使用
SELECT * FROM foo GROUP BY bar ORDER BY bar DESC
没有经历任何速度惩罚,因为无论如何将对分组的场进行分类.顺便说一下,当排序不重要时,你可以通过使用ORDER BY NULL来获得(小)加速.