gpt4 book ai didi

sql - 按月和年分组

转载 作者:行者123 更新时间:2023-12-05 01:39:53 25 4
gpt4 key购买 nike

我正在尝试计算按月和年分组的实例。

SELECT 
(MONTH(CAST(t1.some_date as DATE)) + ' ' + YEAR(CAST(t1.some_date as DATE))) as Issue_Month,
COUNT(*) as c
FROM
(sub query) t1
GROUP BY
(MONTH(CAST(t1.some_date as DATE)) + ' ' + YEAR(CAST(t1.some_date as DATE)))

Error line 2: '+' cannot be applied to bigint, varchar(1)

我尝试将 + 换成 & & || 来构建所需的字符串,但我没有运气。


如何生成如下表:

Month Year  |  c

我如何生成这张表:

Month  |  Year  |  c

最佳答案

您可以使用 date_format() :

SELECT 
date_format(CAST(t1.some_date as DATE), '%m %Y') as Issue_Month,
COUNT(*) as c
FROM
(sub query) t1
GROUP BY
date_format(CAST(t1.some_date as DATE), '%m %Y')

关于sql - 按月和年分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57563919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com