+---------------+------------+
|Processing_date|Contaminated|
+---------------+------------+
|2000/01/01 | FALSE |
|2000/01/02 | TRUE |
|2000/01/03 | FALSE |
|2000/01/04 | FALSE |
+---------------+------------+
I'm trying to figure out how to do a select where I have a column 'ToBeChecked' based on the contaminated column such that ToBeChecked is true for all following rows.
+---------------+------------+------------------+
|Processing_date|Contaminated|item_to_be_checked|
+---------------+------------+------------------+
|2000/01/01 | FALSE |FALSE |
|2000/01/02 | TRUE |TRUE |
|2000/01/03 | FALSE |TRUE |
|2000/01/04 | FALSE |TRUE |
|2000/01/05 | FALSE |TRUE |
+---------------+------------+------------------+
I figure I need to use something like Lag and/or Over
However I don't think I'm looking to partition the data and I can only get Lag to work on one row at present!
SELECT Processing_date, LAG (Contaminated, 1, 0) OVER (ORDER BY processing_date ) as item_to_be_checked
Which yields:
+---------------+------------+------------------+
|Processing_date|Contaminated|item_to_be_checked|
+---------------+------------+------------------+
|2000/01/01 | FALSE |FALSE |
|2000/01/02 | TRUE |TRUE |
|2000/01/03 | FALSE |TRUE |
|2000/01/04 | FALSE |FALSE |
|2000/01/05 | FALSE |FALSE |
+---------------+------------+------------------+