Finding first occurence of multiples value in every group sort by date in SQL

后端 未结 1 994
既然无缘
既然无缘 2021-01-27 18:26

I have a table with every operations that appends before an event group by another value.

There is only 3 operations: R, E, P

+ ----------+----------+--------         


        
1条回答
  •  粉色の甜心
    2021-01-27 19:00

    If I followed you correctly, you can filter on records where order is greater or equal than blocking, and then do conditional aggregation:

    select
        rollcycle,
        blocking,
        max(iif(operation = 'R', 1, 0)) R,
        max(iif(operation = 'E', 1, 0)) E,
        max(iif(operation = 'P', 1, 0)) P
    from mytable 
    where order >= blocking
    group by rollcycle, blocking
    

    0 讨论(0)
提交回复
热议问题