日期:2014-05-18  浏览次数:20451 次

把子查询所得到的列作为运算列
SQL code
SELECT PID,SaleOrderID,MaterialID,NewOrderNum,OldOrderNum,OldBuyIn  
FROM st_NeedBuyIn AS A
WHERE EXISTS
(    SELECT MaterialID,Number 
    FROM HtSaleProductDetail AS B
    WHERE SaleProductID=(
        SELECT AlreadySaleProduct FROM HtSaleOrder WHERE PID=24
                 )     AND A.MaterialID=B.MaterialID)

我想把别名B表中的Number,作为别名A表中的运算列,也就是OldBuyIn=OldBuyIn * B.Number,能否实现,请各位指点,谢谢!

------解决方案--------------------
SQL code
SELECT PID,SaleOrderID,MaterialID,NewOrderNum,OldOrderNum,(OldBuyIn*B.Number) OldBuyIn  
FROM st_NeedBuyIn AS A
join HtSaleProductDetail AS B on A.MaterialID=B.MaterialID
join (SELECT AlreadySaleProduct FROM HtSaleOrder WHERE PID=24) as C ON B.SaleProductID=C.AlreadySaleProduct