【发布时间】:2021-11-12 03:08:20
【问题描述】:
这是我的第一个查询,显示每年每月新增的客户数量
select count(name) AS CUSTOMER,
extract(year from create_date) as yr,
extract(month from create_date) as mon
from x
group by extract(year from create_date),
extract(month from create_date)
order by yr desc, mon desc;
| CUSTOMER | YR | MON |
|---|---|---|
| 3 | 2019 | 07 |
| 4 | 2015 | 02 |
| 100 | 2014 | 09 |
| 3 | 2014 | 04 |
我试过查询
SELECT MAX(count(*))
FROM x
GROUP BY create_date;
在我得到的结果中;
| MAX(COUNT(*)) |
|---|
| 100 |
需要查看结果中的年份和月份。
如何做到这一点?
【问题讨论】:
-
您的问题有几个格式问题,但是,忽略这一点,您是否尝试过解析日期的年份和月份?
to_number(to_char(create_date, 'YYYYMM')).