hive sql 行列转换

-- 对一张大表的每一行,后面加多种label值
-- 其实就是笛卡尔积,举例
-- SELECT * FROM dev.dev_jiadian_user_yuge_temp 
-- CROSS JOIN
-- (
--     SELECT 0 AS label
--     UNION ALL
--     SELECT 1 AS label
--     UNION ALL
--     SELECT 2 AS label
-- )t;

-- 方法二
-- 使用数组,然后进行转置操作
-- 注意k是flag别名,必不可少

SELECT *
FROM
(
SELECT *,
       Array(0,1,2) AS flag
FROM
    dev.dev_jiadian_user_yuge_temp
 )t
lateral view  explode(flag)k AS label
;

-- 

  

参考:https://blog.csdn.net/wangguohe/article/details/79386917

         https://blog.csdn.net/dreamingfish2011/article/details/51250641

       

posted @ 2018-11-08 17:14  静悟生慧  阅读(1618)  评论(0编辑  收藏  举报