create table Product_Price
(
id int,
dt date,
SellerName varchar(20),
Product varchar(10),
ShippingTime varchar(20),
Price money
)
insert into Product_Price values (1, '2012-01-16','Sears','AA','2 days',32)
insert into Product_Price values (2, '2012-01-16','Amazon', 'AA','4 days', 40)
insert into Product_Price values (3, '2012-01-16','eBay','AA','1 days', 27)
insert into Product_Price values (4, '2012-01-16','Walmart','AA','Same day', 28)
insert into Product_Price values (5, '2012-01-16','Target', 'AA','3-4 days', 29)
insert into Product_Price values (6, '2012-01-16','Flipcart','AA',NULL, 30)
select *
from
(select dt, product, SellerName, sum(price) as price
from product_price group by dt, product, SellerName) t1
pivot (sum(price) for SellerName in ([amazon],[ebay]))as bob
)
我想在输出中再增加 2 列(一列是AmazonShippinTime
另一列eBayshippintime
)。我怎样才能得到这些?小提琴:http ://sqlfiddle.com/#!3/2210d/1