我想按升序排序上一年的行,并按降序排列当前年份的行。 这是我的疑问:
SELECT WEEKOFYEAR(DATE) AS WEEK,
YEAR(DATE) YEAR,
COUNT(id) WeekAvg
FROM `user_appoint`
WHERE user_appoint.comp_id=123
GROUP BY WEEK(DATE) , YEAR(DATE)
ORDER BY YEAR(DATE) ASC;
,输出为:
week Year WeekAvg
------ ------ ---------
46 2014 3
47 2014 1
48 2014 6
52 2014 1
12 2015 1
11 2015 1
5 2015 1
但我的预期输出是:
week Year WeekAvg
------ ------ ---------
46 2014 3
47 2014 1
48 2014 6
52 2014 1
5 2015 1
11 2015 1
12 2015 1
答案 0 :(得分:1)
试试吧
SELECT WEEKOFYEAR(DATE) AS WEEK,
YEAR(DATE) YEAR,
COUNT(id) WeekAvg
FROM `user_appoint`
WHERE user_appoint.comp_id=123
GROUP BY WEEK(DATE) , YEAR(DATE)
ORDER BY YEAR(DATE) ASC, WEEKOFYEAR(DATE) ASC;