oracle 显示销售的月份以及该月份按销售额降序排列的销售数量

5hcedyr0  于 2023-11-17  发布在  Oracle
关注(0)|答案(6)|浏览(123)

显示销售的月份以及该月份按销售额降序排序的销售数量。
我已经使用提取函数提取月从日期,但它给了月号不是该月的全名

select extract(month from sldate) as month, count(sid) as number_sale from sale 
 group by sldate  
order by sid desc

字符串
这是table
销售表

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

jei2mxaa

jei2mxaa1#

这回答了最初的问题标记为MySQL。
您不需要只提取月份,而是需要将其与年份结合合并,因为您不希望将不同年份的同一个月的销售额混合在一起,因此使用year_month,然后使用monthname()来获得月份的名称:

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

字符串
参见demo
结果如下:

| month    | number_sale |
| -------- | ----------- |
| February | 2           |
| January  | 2           |
| March    | 1           |
| June     | 1           |

mo49yndu

mo49yndu2#

select to_char(sldate,'Month') as Month,count(*) as number_sale from sale group by to_char(sldate,'Month') order by count(*) desc这是更简单的解决方案

soat7uwm

soat7uwm3#

SELECT TO_CHAR(SLDATE, 'Month') Month, COUNT(SALEID) NUMBER_SALE FROM Sale GROUP BY TO_CHAR(SLDATE, 'Month') ORDER BY NUMBER_SALE DESC

字符串

disbfnqx

disbfnqx4#

select to_char(sldate,'Month') Month, 
 count(to_char(sldate,'Month')) NUMBER_SALE
 from sale  group by (to_char(sldate,'Month')) 
 order by  NUMBER_SALE desc

字符串
1.显示销售的月份和该月份完成的销售数量,按销售额降序排列。

输出

MONTH   NUMBER_SALE
January     2
February    2
March       1
June        1

o8x7eapl

o8x7eapl5#

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

字符串

bq3bfh9z

bq3bfh9z6#

检查下面的查询

SELECT TO_CHAR(SLDATE,'Month')"MONTH", COUNT(SID) AS NUMBER_SALE
FROM SALE
GROUP BY TO_CHAR(SLDATE,'Month')
ORDER BY COUNT(SID) DESC

字符串

相关问题