62,046
社区成员
发帖
与我相关
我的任务
分享
select ID,BrandID,ProductName,
(case tier when 1 then T1 when 2 then T2 else tier3 end) As Price from
(select Product.*,UserBrandLevel.tier from Product
Left join UserBrandLevel on Product.BrandID=UserBrandLevel.BrandID and UserID=@UserID) as P
--或在存储过程里通过游标遍历添加数据到临时表看看
SELECT P.ID
,P.BrandID
,P.ProductName
,Price=(
SELECT (case tier when 1 then T1 when 2 then T2 else T3 end)
FROM UserBrandLevel
WHERE UserID=@UserID AND P.BrandID=BrandID
)
FROM Product P
SELECT P.ID
,P.BrandID
,P.ProductName
,Price=(case UBL.tier
when 1 then T1
when 2 then T2
else T3 end)
FROM Product P LEFT JOIN
(SELECT * FROM UserBrandLevel WHERE UserID=@UserID
) UBL ON P.BrandID=UBL.BrandID