I have a query that joins different tables does some calculations and collects the data in the following format: (same data is provided in excel format in the link below)
sample data can be found here: https://docs.google.com/spreadsheets/d/1zZ3e8L0rYQYIiK9XKlEVVZVhM4atdzKt/edit?usp=drive_link&ouid=114233428136510498080&rtpof=true&sd=true
What I want is a query to strip out all the records for each ID after the 'DELIVERY' type record. i.e. for the first ID, it should keep first 6 records, for the second ID, it should keep first 5 records, and so on. If there are mutiple records with type= ‘Delivery’ per ID, then it should drop records after the first ‘Delivery’ type record. How can I achieve this?
How I want my data is:
My current query is:
SEL t1.ID,
t3.TIME,
t2.TYPE,
ROW_NUMBER() OVER (PARTITION BY t1.ID
ORDER BY t3.TIME) SEQ
FROM master t1
INNER JOIN scan t3
ON t1.ID = t3.ID
INNER JOIN lookup t2
ON t3.CODE = t2.CODE