There is a postgresql table with data
-id -name -datetime -count -price I want to display only those values in which in the last 2 hours the price (or quantity) increased by X times or by Y.
so far the only doing
select * from table where datetime >now()-INTERVAL '2 hours' How to do this?
Example
1 Tovar1 29.10.2017 11:12:13 3 10 2 Tovar2 29.10.2017 11:10:12 0 15 3 Tovar1 29.10.2017 12:00:00 100 10 that is, the quantity of goods1 became 100, and it was less than 2 hours 3. It is necessary to deduce in response to Commodity1 (well, if the number of times increased, it would also be good)
select t1.name, t1.price-t2.price from table t1 inner join table t2 on t1.name = t2.name and t1.datetime > t2.datetime where t1.datetime >now()-INTERVAL '2 hours' and t2.datetime >now()-INTERVAL '2 hours' and (t1.price - t2.price) > Yschematically like this - Viktorov