Postgres - Having Group By Min Of Date Time And Status
I would like to retrieve car_id from the below table which have min (svc_date) with status=A . expected is 103 and 100 which have status 'A' because it have the status A with
Solution 1:
Really, it is hard to understand to you:
with cte as (
select
car_id ,
status,
rank() OVER (
PARTITIONBY car_id
ORDERBY svc_date )
from car_tbl
)
select*from cte
where rank =1and status ='A'
| CAR_ID | STATUS | RANK |
--------------------------
| 100 | A | 1 |
| 103 | A | 1 |
Post a Comment for "Postgres - Having Group By Min Of Date Time And Status"