gpt4 book ai didi

mysql - 使用mysql查询将两列值合并到一个列中

转载 作者:行者123 更新时间:2023-11-29 21:40:37 24 4
gpt4 key购买 nike

我得到不同格式的输出,这是我的查询:

SELECT
COUNT(lead_id) AS `leads`,
Month(FROM_UNIXTIME(`created_at`)) AS `Month`
FROM `lead`
WHERE YEAR(FROM_UNIXTIME(`created_at`)) = YEAR(CURDATE())
GROUP BY Month(FROM_UNIXTIME(`created_at`));

输出:

Month
312c31
322c31
332c31
342c31
352c31
362c31
372c31
382c31
392c31
31302c31
31312c31
31322c31

所需输出:

month
1,1
2,23
3,4
5,6
6,34
7,76
8,2
9,3
10,5
11,4
12,1

最佳答案

你可以试试这个:

SELECT
CAST(
CONCAT(
MONTH(FROM_UNIXTIME(`created_at`)),
',',
COUNT(lead_ID)
) AS CHAR
) AS 'Month'
FROM lead
WHERE `created_at` BETWEEN UNIX_TIMESTAMP(DATE_FORMAT(NOW(), "%Y-01-01")) AND UNIX_TIMESTAMP(DATE_FORMAT(NOW(), "%Y-12-31"))
GROUP BY MONTH(FROM_UNIXTIME(`created_at`))

关于mysql - 使用mysql查询将两列值合并到一个列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34564945/

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