且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

迭代获取数据框列的最大值,添加一个并重复 spark/sql 中的所有行

更新时间:2023-11-18 23:22:46

您的问题的解决方案可以是:

A solution to your problem can be this:

SELECT 
        system_id, 
        (min(node_id) over ())-1+row_number() OVER (ORDER BY -node_id desc) node_id, 
        `level_4`, `level_5`, `level_6`, `level_7` 
    FROM 
        taxonomies

如果你想使用join来做到这一点,方法如下:

If you want to do this using join, this is the way:

SELECT 
    system_id, 
    t2.min_node-1+row_number() OVER (ORDER BY -tn.node_id desc) node_id, 
    `level_4`, `level_5`, `level_6`, `level_7` 
FROM 
    taxonomies tn 
cross join 
    (SELECT min(node_id) as min_node FROM taxonomies) as t2

如果你想使用子查询来做到这一点,方法如下:

If you want to do this using sub-query, this is the way:

SELECT 
        system_id, 
        (select min(node_id) from taxonomies)-1+row_number() OVER (ORDER BY -node_id desc) node_id, 
        `level_4`, `level_5`, `level_6`, `level_7` 
    FROM 
        taxonomies