假设我有以下walletid的
walletid
ab2
ab2
cd3
现在我想添加一个ID来将其更改为此:
id walletid
1 ab2
1 ab2
2 cd3
答案 0 :(得分:0)
你在这里
SELECT wallets.walletid, wallets_distinct_ids.id
FROM wallets INNER JOIN
(SELECT walletid, row_number() OVER () as id
FROM
(SELECT DISTINCT walletid
FROM wallets) AS wallets_distinct) AS wallets_distinct_ids
ON wallets.walletid = wallets_distinct_ids.walletid
说明:
walletid
的不同值walletid
值walletid
分配唯一的ID