我有一张桌子,如下所示,
uname date value
fb 2019-09-13 10
uk 2019-09-13 20
fb 2019-09-14 30
us 2019-09-13 40
us 2019-09-14 50
输出应如下
unmae 2019-09-13 2019-09-14
fb 40 0
us 40 50
uk 20 0
select queue_name,kv1('2019-06-03') AS A_v1 from
(
select queue_name,map_agg(wb,components_processed) as kv1
from hr_flash_fd_reviewer_policy group by 1
)
答案 0 :(得分:0)
您可以使用条件聚合。请注意,这要求您事先知道日期列的可能值。
SELECT
uname,
SUM(CASE WHEN mydate = date '2019-09-13' THEN value ELSE 0 END) AS "2019-09-13",
SUM(CASE WHEN mydate = date '2019-09-14' THEN value ELSE 0 END) AS "2019-09-14"
GROUP BY uname
ORDER BY uname
NB:date
对于列名是一个非常糟糕的选择,因为它与保留关键字冲突。我在查询中将其重命名为mydate
。