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)

  • It is not entirely clear how the data in the table lie. An example would be a few lines, and those that need to be selected. And it is not clear, compared with what the price rose - Viktorov
  • @lDrakonl changed - Rakzin Roman
  • You write about the price in question, and in the example you are talking about quantity. I'm confused - Viktorov
  • @lDrakonl I need this and that. Write one thing, I will write the principle and the other - Rakzin Roman
  • one
    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) > Y schematically like this - Viktorov

0