给定名为
events
的表,其中包含列 dt (timestamp)
和 type (event type, example buy, sell, other)
我想明智地了解
2021
中发生的所有事件。结果应包含 2 列:
用分号和空格分隔类型。
这是我的询问:
获取第 1 列:
Quarter
select concat('Q', Quarter(dt), "'", RIGHT(YEAR(dt), 2)) as c1
from events
解决这个问题的正确方法是什么?
select group_concat(concat(type, '=', cnt)) as c2
from (
select type, count(*) as cnt, quarter(dt) as qtr
from events where year(dt) = 2021
group by type, qtr
放入子查询中,并在分组中使用它。
concat('Q', Quarter(dt), "'", RIGHT(YEAR(dt), 2))