Guest User

Untitled

a guest
Jan 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. product | action | date | amount
  2. book | 1 | 1/5/2017 | 100
  3. book | -1 | 3/6/2017 | 30
  4.  
  5. product | income | outcome | sum
  6.  
  7. select product
  8. , date -- дата
  9. ,case when action = 1 then action else null end income --сколько пришло
  10. ,case when action = -1 then action else null end outcome --сколько ушло
  11. ,sum(action) sumaction -- разница между пришло/ушло
  12. , (amount + sumaction) a1 --сумма
  13. from table_name --название таблицы
  14. where date between to_date('01.01.2017', 'dd.mm.yyyy') and
  15. to_date('02.01.2017', 'dd.mm.yyyy') -- условие на дату
Add Comment
Please, Sign In to add comment