我有一个列有列的表格..
column1 column2 column3 column4 column5
我希望数据在第二列中填写如下。
其中colum1,3,4,5 ...用户将给出值...
在第2列中,其值应为自动排序,如下所示......
column1 column2 column3 column4 column5
1 1 one one one
1 2 two two two
1 3 three three three
2 1 one one one
2 2 two two two
2 3 three three three
3 1 one one one
3 2 two two two
3 3 three three three
好心的人给你的建议......谢谢你! CYA!
答案 0 :(得分:1)
似乎你想为每一行赋予column1中相等值的不同值。这可以通过窗口函数来完成:
SELECT column1,
row_number() over (partition by column1) as column
FROM some_table
我不明白你想要在第3,4和5列中拥有什么
答案 1 :(得分:1)
根据您的平台,以下可能会有效...
UPDATE
<your-table>
SET
column2 = ROW_NUMBER() OVER (PARTITION BY column1)
修改强>
正如马丁在评论中所说的那样......
WITH
windowed_table
AS
(
SELECT
column2,
ROW_NUMBER() OVER (PARTITION BY column1 ORDER BY column1) AS row_number
FROM
my_table
)
UPDATE
windowed_table
SET
column2 = row_number