SQL UPDATE in a SELECT rank over Partition sentence

后端 未结 2 883
渐次进展
渐次进展 2021-01-07 05:35

There is my problem, I have a table like this:

Company, direction, type, year, month, value, rank

When I create the table, rank is 0 by def

2条回答
  •  长情又很酷
    2021-01-07 06:32

    You can to it simply like this. It is not that commonly known but you can make UPDATE on a SELECT

    UPDATE 
        (SELECT 
            company, direction, TYPE, YEAR, MONTH, VALUE, 
            RANK() OVER (PARTITION BY direction, TYPE, YEAR, MONTH ORDER BY VALUE DESC) AS NEW_RANK
        FROM table1) a
    SET RANK = NEW_RANK;
    

提交回复
热议问题