我有以下查询:
SELECT
DATE_FORMAT( DATE, '%M' ) AS MONTH,
DATE_FORMAT( DATE, '%y' ) AS YEAR,
DEVICE,
COUNT( * ) AS cnt
FROM users
GROUP BY YEAR, MONTH, DEVICE
我试图按年和月订购,所以类似于:
我该怎么做?
答案 0 :(得分:1)
要订购您想要的商品,请使用ORDER BY:
SELECT DATE_FORMAT( DATE, '%M' ) AS
MONTH , DATE_FORMAT( DATE, '%y' ) AS year, DEVICE, COUNT( * ) AS cnt
FROM users
GROUP BY year, MONTH , DEVICE
ORDER BY DATE_FORMAT( DATE, '%y' ), DATE_FORMAT( DATE, '%m' )
答案 1 :(得分:1)