gpt4 book ai didi

mysql - Mysql表水平排序

转载 作者:行者123 更新时间:2023-11-29 10:49:30 26 4
gpt4 key购买 nike

我有以下查询:

SELECT asunto, MONTH(created_at) as mes, COUNT(turno) as numero
FROM tikets
where id_sucursal = 1 and subasunto = 'Pago' GROUP BY asunto, mes ORDER BY mes ASC

这给了我这样的结果:

enter image description here

我想知道如何进行咨询才能使其发挥作用,或者我必须做什么。感谢您的关注

enter image description here

最佳答案

使用条件聚合:

SELECT t.asunto, 
SUM(MONTH(t.created_at) = 2) as month_2,
SUM(MONTH(t.created_at) = 3) as month_3,
SUM(MONTH(t.created_at) = 4) as month_4,
SUM(MONTH(t.created_at) = 5) as month_5
FROM tikets t
WHERE t.id_sucursal = 1 AND t.subasunto = 'Pago'
GROUP BY asunto;

需要注意的是:在处理月份时,您通常需要考虑年份。

关于mysql - Mysql表水平排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43987472/

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