【发布时间】:2022-10-12 23:09:01
【问题描述】:
标签: sql postgresql pivot
标签: sql postgresql pivot
从您的示例中,我将使用以下内容:
Select tbl.Month, MAX(tbl.ClosedCount) as closedCount, MAX(tbl.RepliedCount) as RepliedCount
From
((select closedDate as Month, COUNT(*) ClosedCount,'' as RepliedCount
from Dummy
group by ClosedDate)
UNION
(select repliedDate as Month, '' as ClosedCount, COUNT(*) RepliedCount
from Dummy
group by repliedDate)) as tbl
group by Month
我使用以下方法创建了测试:
CREATE TABLE Dummy
([ID] int, [ClosedDate] int, [RepliedDate] int)
;
INSERT INTO Dummy
([ID], [ClosedDate], [RepliedDate])
VALUES
(1, 10, 11),
(2,12,11),
(3,10,12),
(4,11,12)
;
你可以在http://sqlfiddle.com/#!18/c8ae79/3看到我的例子
【讨论】: