0

クエリにあるようにレコードを並べ替えたい:

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 を持っています

何か考えはありますか

**************************編集

これは、新しい列を配置order by 'month desc'または追加して、それによって注文したときの結果です。 ここに画像の説明を入力

ご覧のとおり、問題は order_quantity の注文が最優先されることです

4

0 に答える 0