我希望将记录按照查询中的顺序排序:
SELECT `month`, SUM(order_quantity) AS order_quantity FROM" +
"( SELECT MONTH(date_livraison) AS month, COUNT(*) AS order_quantity FROM" +
" bon_livraison GROUP BY MONTH(date_livraison) UNION ALL " +
"SELECT MONTH(DATE_SUB(NOW(), INTERVAL 12 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 11 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 10 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 9 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 8 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 7 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 6 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 5 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 4 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 3 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 2 MONTH)) AS month, 0 order_quantity UNION ALL " +
" SELECT MONTH(DATE_SUB(NOW(), INTERVAL 1 MONTH)) AS month, 0 order_quantity ) a GROUP BY `month` ORDER BY `month`
但总是我有1 ...... 12
你知道吗
************************** EDIT
这是我放order by 'month desc'
或添加新列的结果,并且我按照它排序:
如果你看,问题是order_quantity的顺序具有第一优先级