我有以下代码
Select MR.MRPRoductId,MR.PartNo, E.MaterialName as Producttomake,EP.MaterialName as NeededProduct,(MR.ApprovedQty*PCM.NeededQuantity-isnull(SUM(ISS.IssuedQty),0))as Needed,PCM.NeededProductPartNo,
EP.UOM,ISNULL(SM.Quantity,0)as Available from Material_Requisition MR
join Productconversion_master PCM on MR.PartNo=PCM.ConvertedProductPartNo
Left join ProductConversion_IssueSlip ISS on PCM.NeededProductPartNo=ISS.IssuedPartNo
join ElectricalProducts E on MR.PartNo=E.PartNo join ElectricalProducts EP on PCM.NeededProductPartNo=EP.PartNo
Left join StockMaster SM on PCM.NeededProductPartNo=SM.PartNo and SM.LocationId='LOC_001' where MR.MRID='TFIPL/MR/CON/NR/2013-14/00001'
group by EP.MaterialName,MR.MRPRoductId,MR.PartNo,E.MaterialName,
MR.ApprovedQty,PCM.NeededQuantity,PCM.NeededProductPartNo,EP.UOM,SM.Quantity
此查询的结果如下
我想只选择Needed> 0 .how将其添加到where where
中答案 0 :(得分:1)
两个选项。
选项1 - 我认为最简单
SELECT list
, of
, columns
FROM (
<your query goes here>
) As a_subquery
WHERE needed > 0
选项2
<your_query goes here>
HAVING (MR.ApprovedQty*PCM.NeededQuantity-isnull(SUM(ISS.IssuedQty),0)) > 0
您不能在此方案中使用WHERE
条件,因为它适用于聚合。与聚合相当的是HAVING
子句(在 GROUP BY
之后放置)