Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- product | action | date | amount
- book | 1 | 1/5/2017 | 100
- book | -1 | 3/6/2017 | 30
- product | income | outcome | sum
- select product
- , date -- дата
- ,case when action = 1 then action else null end income --сколько пришло
- ,case when action = -1 then action else null end outcome --сколько ушло
- ,sum(action) sumaction -- разница между пришло/ушло
- , (amount + sumaction) a1 --сумма
- from table_name --название таблицы
- where date between to_date('01.01.2017', 'dd.mm.yyyy') and
- to_date('02.01.2017', 'dd.mm.yyyy') -- условие на дату
Add Comment
Please, Sign In to add comment