当(sumofqtyreturn + sumofqtyissued)大于sumofqtyordered时,我想生成错误消息。我想执行此验证检查,以便当用户输入大于余额的值(qtyreturn或qtyissued)时,系统应该产生错误。可以这样做吗?
这是我查询的sql视图:
SELECT i.itemNo, Nz(TotalOrdered,0), Nz(TotalReturned,0), Nz(TotalIssued,0),
(Nz(TotalOrdered,0)-Nz(TotalIssued,0)+Nz(TotalReturned,0)) AS Balance
FROM ((item AS i
LEFT JOIN (SELECT itemno, Sum(qtyordered) AS TotalOrdered
FROM delivered_item
GROUP BY itemno) AS d ON d.itemno=i.itemno)
LEFT JOIN (SELECT itemno, Sum(qtyreturn) AS TotalReturned FROM item_return
GROUP BY itemno) AS r ON r.itemno=i.itemno)
LEFT JOIN (SELECT itemno, Sum(qtyissued) AS TotalIssued FROM item_issued
GROUP BY itemno) AS iss ON iss.itemno=i.itemno
或者any1对如何通知/警告用户qtyissued / qtyreturn有什么问题有其他好主意?(值太大)
答案 0 :(得分:2)
这是一般性的想法。
SELECT q.AText,
q.SumOfANumber,
q.SumOfADecimal,
IIf([SumOfANumber]-[SumOfADecimal]<0,"Problem!","Yes") AS IsOkay
FROM (SELECT t.AText,
Sum(t.ANumber) AS SumOfANumber,
Sum(t.ADecimal) AS SumOfADecimal
FROM Table1 As t
GROUP BY t.AText) AS q;
聚合查询成为子查询,并在主查询中比较相关字段。我已经为Table1使用了别名,因此你有Table1 As t
和子查询。