with full_data as (select time_bucket_gapfill('1 day':: interval, "recode_time") full_time,
meter_code,
interpolate(max(max_reading)) max_reading
from water_downsampling_day
where meter_code = 'METXJJSZXNSB1'
and (recode_time >= '2024-05-01 00:00:00'::timestamp - interval '1 day' and
recode_time <= '2024-05-31 23:59:59'::timestamp)
group by full_time, meter_code)
select to_char(full_time, 'YYYY-MM-DD'),
full_time,
coalesce(max_reading - lag(max_reading) over (partition by meter_code order by full_time), 0) row_diff
from full_data;
2024-05-01, the reading is: 1
When SQL adds: where to_char (full_time,'YYYY-MM-DD ')>=‘2024-05-01’;
with full_data as (select time_bucket_gapfill('1 day':: interval, "recode_time") full_time,
meter_code,
interpolate(max(max_reading)) max_reading
from water_downsampling_day
where meter_code = 'METXJJSZXNSB1'
and (recode_time >= '2024-05-01 00:00:00'::timestamp - interval '1 day' and
recode_time <= '2024-05-31 23:59:59'::timestamp)
group by full_time, meter_code)
select to_char(full_time, 'YYYY-MM-DD'),
coalesce(max_reading - lag(max_reading) over (partition by meter_code order by full_time), 0) row_diff
from full_data
where to_char(full_time, 'YYYY-MM-DD') >= '2024-05-01';
2024-05-01, the reading changed to: 0
This is really strange. May I ask, have any of you encountered this kind of problem?