如何在不使用自定义udf或左连接的情况下在配置单元中执行关键操作?

f87krz0w  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(408)

样本输入:

PARTY      |TYPE | TIMESTAMP
-------------------------------------
135761103  |AA   |2017-04-24 11:18:46.233  
135761103  |BB   |2017-04-24 11:19:18.436

期望输出:

PARTY |AA_TIMESTAMP|BB_TIMESTAMP   
--------------------------------
135761103  |2017-04-24 11:18:46.233 |2017-04-24 11:19:18.436
hwamh0ep

hwamh0ep1#

你可以用 CASE & GROUP BY 组合。比如:

SELECT
    PARTY,
    max(CASE WHEN TYPE = 'AA' THEN TIMESTAMP END) AS AA_TIMESTAMP,
    max(CASE WHEN TYPE = 'BB' THEN TIMESTAMP END) AS BB_TIMESTAMP
FROM 
    MY_TAB
GROUP BY
    PARTY

相关问题