我有 3 张桌子
table 1 "Sale" that saved date of user sale
table 2 "ProductFactor" that saved factorid and productid in wich factoreid
tabel 3 "Product" that saved productid and product name
我想在 3 表中选择这个结果:
显示用户 factorid +price+ saledate + 在这个 factorid 中可用的任何产品名称
但是什么时候这样做,例如当在一个具有 3 个 productid 的 factorid 中时,显示如下:
date factoreid name price
2013-09-25 1 x 18261256 2013-09-25 1 y 2365560.0000 2013-09-25 2 w 5500.0000 2013-09-25 3 z 50000.0000 2013-09-25 1 k 324.0000
我想展示这个:
date factoreid name price
2013-09-25 1 x,y,k sum of 3 product name 2013-09-25 2 w 5500.0000 2013-09-25 3 z 50000.0000
CREATE PROCEDURE [dbo].[GetUserSaleReport]
@CurrentUserId uniqueidentifier
AS
BEGIN
SELECT dbo.Sale.SaleDate,dbo.ProductFactor.FactoreId,dbo.Product.ProductName,dbo.Product.Price
FROM Sale INNER JOIN ProductFactor ON
dbo.Sale.FactoreId=dbo.ProductFactor.FactoreId
INNER JOIN dbo.Product ON dbo.ProductFactor.ProductId=dbo.Product.ProductId
WHERE dbo.Sale.UserId = @CurrentUserId AND dbo.Sale.FactoreId=dbo.ProductFactor.FactoreId AND dbo.ProductFactor.ProductId=dbo.Product.ProductId
ORDER BY dbo.Sale.SaleDate
END