显示销售月份和该月的销售数量,按销售降序排列。
我已经使用了提取功能从日期中提取月份,但是它给出的是月份编号而不是月份的全名
select extract(month from sldate) as month, count(sid) as number_sale from sale
group by sldate
order by sid desc
这是桌子
销售表
SALEID SID SLDATE
1001 1 01-JAN-14
1002 5 02-JAN-14
1003 4 01-FEB-14
1004 1 01-MAR-14
1005 2 01-FEB-14
1006 1 01-JUN-15
预期结果
MONTH NUMBER_SALE
February 2
January 2
March 1
June 1
答案 0 :(得分:1)
SELECT TO_CHAR(SLDATE, 'Month') Month, COUNT(SALEID) NUMBER_SALE FROM Sale GROUP BY TO_CHAR(SLDATE, 'Month') ORDER BY NUMBER_SALE DESC
答案 1 :(得分:0)
您需要将其与年份相结合,而不是仅提取月份,因为您不想将不同月份的同一月的销售额混合使用,因此请使用year_month
然后使用{{3} }以获取月份的名称:
select
monthname(concat(extract(year_month from sldate), '01')) as month,
count(sid) as number_sale
from sale
group by month
order by number_sale desc
请参见monthname()
。
结果:
| month | number_sale |
| -------- | ----------- |
| February | 2 |
| January | 2 |
| March | 1 |
| June | 1 |
答案 2 :(得分:0)
select to_char(sldate,'Month') as Month,count(*) as number_sale from sale group by to_char(sldate,'Month') order by count(*) desc
这是更简单的解决方案
答案 3 :(得分:-1)
select to_char(sldate,'Month') as month,count(sid) as NUMBER_SALE from sale
group by to_char(sldate,'Month')
order by NUMBER_SALE desc
答案 4 :(得分:-2)
检查以下查询
SELECT TO_CHAR(SLDATE,'Month')"MONTH", COUNT(SID) AS NUMBER_SALE
FROM SALE
GROUP BY TO_CHAR(SLDATE,'Month')
ORDER BY COUNT(SID) DESC