Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with odczyty2 as (
- with odczyty as (
- select
- dev.code as dev_code,
- coalesce(mcd.value_as_double, mcd.value_as_long) as value_as_number,
- mcd.container_id as con_id,
- mcd."timestamp",
- us.email
- from devices dev
- left join device_parameters dev_par on dev_par.device_id = dev.id
- left join measuring_containers mc on mc.device_parameter_id = dev_par.id
- left join measuring_containers_data mcd on mcd.container_id = mc.id
- left join "identity".users us on us.id = dev.owner_id
- where
- dev.owner_id = 65
- and
- dev_par.parameter_id = 24
- and
- mcd."timestamp" < '2019-06-19'
- and
- mcd."timestamp" > '2019-06-17'
- --order by mcd."timestamp"
- )
- select
- lead (value_as_number, -1)
- over (partition by odczyty.dev_code) as prev_value
- ,
- odczyty.dev_code,
- odczyty.con_id,
- odczyty.value_as_number,
- odczyty."timestamp",
- odczyty.email
- from odczyty
- )
- select
- odczyty2.dev_code,
- odczyty2.con_id,
- odczyty2.prev_value,
- odczyty2.value_as_number,
- odczyty2.value_as_number - odczyty2.prev_value as diff,
- odczyty2."timestamp",
- odczyty2.email
- from odczyty2
- where
- odczyty2.value_as_number - odczyty2.prev_value < 0
- and
- odczyty2.value_as_number - odczyty2.prev_value <= -0.001
- and
- odczyty2.dev_code like '%water%'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement