'How to set occurrence of a user entry in SQL?
This is how I want to set a flag, how to do it in SQL?
| User | Payment | Flag |
|---|---|---|
| U1 | 1500 | 1 |
| U1 | 1500 | 2 |
| U1 | 1500 | 3 |
| U2 | 1500 | 1 |
| U2 | 1500 | 2 |
| U3 | 1500 | 1 |
Solution 1:[1]
use row_number()
select a.*,
row_number()over(partition by user order by payment) as Flag
from table_name a
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
