2

クエリを書きました

SELECT 
    MONTHNAME( create_date ) AS MONTH, 
    COUNT( dollar_value_awarded ) AS monthly_sales_count 
FROM claims 
WHERE spiffid='$id' 
AND create_date BETWEEN '$sdate' AND '$edate' 
GROUP BY MONTH

そしてそれは表示されます

MONTH     monthly_sales_count
April       285
February    134
March       958

私はそれを次のように表示したい:

MONTH     monthly_sales_count
February    134
March       958
April       285

つまり、結果は 1 月から 12 月までに並べ替える必要があります。

4

4 に答える 4

1
SELECT MONTHNAME( create_date ) AS month_name,             --- change this alias
       COUNT( dollar_value_awarded ) AS monthly_sales_count 
FROM claims 
WHERE spiffid = '$id' 
  AND create_date BETWEEN '$sdate' AND '$edate' 
GROUP BY MONTH(create_date)                         --- use the MONTH() function
于 2012-04-11T11:21:39.143 に答える
0

単にORDERBY句を追加します。

SELECT MONTHNAME( create_date ) AS MONTH , COUNT( dollar_value_awarded ) AS monthly_sales_count      
FROM claims 
WHERE   spiffid='$id' and create_date BETWEEN '$sdate' AND '$edate' 
GROUP BY MONTH 
ORDER BY MONTH(create_date)
于 2012-04-11T10:27:47.810 に答える
0

引数MONTH(create_date)として渡すことができると思います:ORDER BY

SELECT MONTHNAME( create_date ) AS MONTH , COUNT( dollar_value_awarded ) AS monthly_sales_count 
FROM claims WHERE spiffid='$id' and create_date 
BETWEEN '$sdate' AND '$edate' 
GROUP BY MONTH
ORDER BY MONTH(create_date) 
于 2012-04-11T09:48:39.977 に答える
0

あなたができる

SELECT MONTHNAME( create_date ) AS MONTH, 
       COUNT( dollar_value_awarded ) AS monthly_sales_count 
  FROM claims 
 WHERE spiffid='$id' and create_date BETWEEN '$sdate' AND '$edate' 
 GROUP BY MONTH, MONTH(create_date)
 ORDER BY MONTH(create_date)
于 2012-04-11T10:18:16.413 に答える