merge - Sql Matching exact DataSets on same table -
i have table contains data such as:
store,product a, 1 a, 2 b, 3 b, 2 c, 3 c, 1 d, 1 d, 2 d, 3
i trying write query gives me replacement store, since store d sells product store sells replacement store store not replacement store d since not have of product store d sells.
so query return following table:
store,store replacement a,- b,- c,- d,a
*note couldn't figure out how make table, ',' represents separation of columns. - equals blank in space
here version work:
select sp.store, sp2.store (select sp.*, count(*) on (partition store) numproducts @storeproduct sp ) sp join @storeproduct sp2 on sp.product = sp2.product , sp.store <> sp2.store group sp.store, sp2.store, numproducts having count(sp2.product) = numproducts;
here sql fiddle.
Comments
Post a Comment