[英]Pivot in aws athena
I have a table as follwos, 我有一张桌子,如下
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
Output should be as folows 输出应如下
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
)
You can use conditional aggregation . 您可以使用条件聚合 。 Please note that this requires that you know in advance the possible values for the date column. 请注意,这要求您事先知道日期列的可能值。
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
is a really bad choice for a column name, since it clashes with a reserved keyword. 注意:对于列名, date
是一个非常糟糕的选择,因为它与保留关键字冲突。 I renamed it to mydate
in the query. 我在查询mydate
其重命名为mydate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.