I m a new SQL leaner, and got my self into a difficult question,
let's say i have this table:
Expand|Select|Wrap|Line Numbers
- create table purchase(
- datePurchase date
- itemiId int,
- nbItemSold int
- cstmrId int
- );
Ex:
Expand|Select|Wrap|Line Numbers
- insert into purchase values
- ('2017-02-01' ,4, 'product1'),
- ('2017-02-01', 3, 'product2'),
- ('2017-02-01', 1, ' product3'),
- ('2017-02-02', 1, 'product1'),
- ('2017-02-02', 2, 'product2'),
- ('2017-02-02', 1, 'product3'),
- ('2017-02-03', 5, 'product2'),
- ('2017-02-03', 1, 'product3'),
- ('2017-02-03', 0, 'product1');
the final table resulting of these difference should contain this datas
2017-02-02, product1, -3
2017-02-02, product2, -1
2017-02-02, product3, 1
2017-02-03, product1, -1
2017-02-03, product2, 3
2017-02-03, product3, 0
the customer doesn't matter. i just want to find the daily difference in selling products