Presto 数据透视
我对 Presto 很陌生,在其中旋转数据时遇到困难。 我使用的方法如下:
select
distinct location_id,
case when role_group = 'IT' then employee_number end as IT_emp_num,
case when role_group = 'SC' then employee_number end as SC_emp_num,
case when role_group = 'HR' then employee_number end as HR_emp_num
from table
where 1=1
and id = 1234
这很好,但是,行中也填充了空值,我想旋转数据,只返回包含相关信息的一行。
我尝试使用 array_agg 函数,该函数会折叠数据,但也会保留空值(例如,它将为第一列返回 null,301166,null)
I am really new to Presto and having trouble pivoting data in it.
The method I am using is the following:
select
distinct location_id,
case when role_group = 'IT' then employee_number end as IT_emp_num,
case when role_group = 'SC' then employee_number end as SC_emp_num,
case when role_group = 'HR' then employee_number end as HR_emp_num
from table
where 1=1
and id = 1234
This is fine, however, null values are also populated for the rows and I would like to pivot the data, to only return one row with the relevant info.
I have tried using the array_agg function, which will collapse the data but it also keeps the null values (e.g. it will return null,301166,null for the first colum)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果每个位置只需要一行,您可以使用
max
与分组依据:If only one row per location is needed you can use
max
with group by: