I have the query and table below, how do I select the 1st line of each category of column TeamboardId?
SELECT * FROM Job WHERE HandLingTimeSeconds = '60'
JobId | TeamboardId |
---|---|
1 | 1 |
2 | 1 |
3 | 1 |
4 | 2 |
5 | 2 |
6 | 2 |
The expected result should be
JobId | TeamboardId |
---|---|
1 | 1 |
4 | 2 |
You can probably use a window function such as ROW_NUMBER()
like in the below query :
WITH j AS
(
SELECT Job.*, ROW_NUMBER() OVER (PARTITION BY TeamboardId ORDER BY JobId) AS rn
FROM Job
WHERE HandLingTimeSeconds = '60'
)
SELECT *
FROM j
WHERE rn = 1
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments