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

这意味着结果应该从一月到十二月排序

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

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 回答
0

Sinmply 添加一个 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-11T10:27:47.810 回答