I'm new in SQL and I want to write a query where we keep the rows where, for the same item:
Everything else is discarted.
I know I have to use LAG function i've not been able to reach to a final query. Can you help?
Thanks in advance
If I understand correctly:
select t.*
from (select t.*,
lag(column1) over (order by ordercol) as prev_column1
from t
) t
where column1 is null and
(prev_column1 = 'end' or prev_column1 is null)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.