Given a dataset with a timestamp and a value, I would like to run a query that for a given day, would return a 0 for that day if a record exists with value 0 or 1 if only non-zero values exist for that day. If there are no records for that day, also return 0.
As an example, with the given data set.
2019-06-20 23.1
2019-06-20 22.4
2019-06-20 23.1
2019-06-18 23.2
2019-06-18 0
2019-06-18 22.8
I would like to have this returned:
2019-06-20 1 -- only non-zero values for 6/20
2019-06-19 0 -- no data for 06/19
2019-06-18 0 -- 06/18 has a zero value
I know I can write a stored procedure to do this, but was hoping I could do it with a query (possibly CTE)