如何使用 hql 制作枢轴 table?

How to make pivot table using hql?

输入:字段

id  title view
id1  我    12
id1  好    23
id2  你    13
id3  你    20
id4  他    11

输出:

id    我   好   你   他
id1   12  23   NaN  NaN
id2   NaN NaN  13   NaN
id3   NaN NaN  20   NaN
id4   NaN NaN  NaN  11

我知道如何使用 python 得到这个结果。但是我不知道如何使用 hive-sql.

来获得它

case when expression

使用条件聚合
select 
 id, 
 max(case when title='我' then view end) as '我',
 max(case when title='好' then view end) as '好',
 max(case when title='你' then view end) as '你',
 max(case when title='他' then view end) as '他'
from tablename
group by id