I have table
ID | number |
---|---|
1 | 4 |
1 | 5 |
1 | 2 |
3 | 5 |
I want to select the minimum number for each ID without deleting duplicates
ID | number | min_number |
---|---|---|
1 | 4 | 2 |
1 | 5 | 2 |
1 | 2 | 2 |
3 | 5 | 5 |
How I can do it?
CodePudding user response:
Assuming you are on a RDBMS that supports modern SQL then you just need to add
MIN(number) OVER (PARTITION BY id) AS min_number
to your SELECT list