create table Products
(
id int,
ProductName varchar(200),
ProductCategory varchar(200),
ProductImage varchar(200),
ProductUri varchar(200),
)
Insert into Products values(135, 'Product X', 'Digital Camera', Null, Null)
Insert into Products values(136, 'Product Y', 'Mobile', Null, Null)
create table Product_Price
(
id int,
ProductId int,
dt date,
SellerName varchar(20),
Available varchar(20),
Offer varchar(20),
Price money,
Shipping money
)
insert into Product_Price values (1, 135,'2012-01-16','Sears','In Stock','30% discount',32.00,2.00)
insert into Product_Price values (2, 135,'2012-01-16','Amazon','In Stock',Null,30.00,NULL)
insert into Product_Price values (3, 135,'2012-01-16','eBay','Just 2 Left',Null,28.00,1.00)
insert into Product_Price values (4, 136,'2012-01-16','Sears','In Stock','30% discount',30.00,6.00)
insert into Product_Price values (5, 136,'2012-01-16','Amazon','In Stock',Null,28.00,4.00)
insert into Product_Price values (6, 136,'2012-01-16','eBay','Out Of stock',Null,Null,Null)
And i want result like this :
ID ProductName ProductCategory ProductImage ProductUri SearsTotal Price(Price+Shipping) SearsAvailablity SearsOffer #Competitors DifferencePercentage(Sears & others) AmazonTotal Price(Price+Shipping) AmazonAvailablity AmazonOffer eBayTotal Price(Price+Shipping) eBayAvailablity eBayOffer 135 Product X Digital Camera NULL NULL 34 In Stock 30% discount 2 15.25423729 30 In Stock NULL 29 Just 2 Left NULL 136 Product Y Mobile NULL NULL 36 In Stock 25% discount 1 12.5 32 In Stock NULL NULL Out Of stock NULL
Step 1 is here : Product price comparison in sql My test is here : http://sqlfiddle.com/#!3/ec1e7/6