Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- item qty
- --------
- 3001 1
- 3003 3
- 3004 1
- 3006 2
- item qty
- ----------
- 3001 2
- 3002 3
- 3006 3
- 3008 6
- item qty
- -----------
- 3001 3
- 3002 3
- 3003 3
- 3004 1
- 3006 5
- 3008 6
- SELECT Item, SUM(qty) as Qty FROM
- (
- SELECT Item, qty FROM warehouse_1
- UNION
- SELECT Item, qty FROM warehouse_2
- ) as a
- GROUP BY item;
- select item,sum(qty) from(
- select item, Qty from warehouse_1 UNION
- select item, Qty from warehouse_2
- )x group by item
- CREATE OR REPLACE VIEW warehouse_3 as
- SELECT coalesce(w1.item,w2.item) as item, w1.qty+w2.qty as qty
- FROM warehouse_1 as w1
- OUTER JOIN warehouse_2 as w2
- ON w1.item = w2.item;
- select * from warehouse_3;
- SELECT item , SUM(qty)
- FROM (
- SELECT item, qty
- FROM warehouse_1
- UNION
- SELECT item, qty
- FROM warehouse_2
- ) AS U GROUP BY item
- create table tbl1(item int,qty int)
- INSERT INTO tbl1
- VALUES(3001,1),(3003,3),(3004,1),(3006,2)
- create table tbl2(item int,qty int)
- INSERT INTO tbl2
- VALUES(3001,2),(3002,3),(3006,3),(3008,6)
- select isnull(t1.item,t2.item) as item,isnull(t1.qty,0)+isnull(t2.qty,0) as qty from tbl1 t1 full outer join tbl2 t2 on t1.item =t2.item
- order by 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement