您好我有两张桌子,分别是tblPOdetails和tblPDdetails
tblPOdetails
PONumber - Item - Qty - Price
12345---------soap------5-------4.50
tblPDdetails
PONumber - Item - Qty - Price
12345---------soap------4-------4.50
我想要的结果
PONumber - Item - Qty - Price
12345---------soap------1-------4.50
该表中的所有列和字段都相同。
现在我要减去tblpodetails.qty - tblpddetails.qty,其中PONumber ='12345'我希望得到该场景的结果,任何人都可以教我脚本。
谢谢!
答案 0 :(得分:1)
如果PONumber
是两个表中的表键,则此查询应该为您提供所需的结果:
SELECT tblPOdetails.PONumber AS PONumber,
tblPOdetails.Item AS Item,
(tblPOdetails.Qty - tblPDdetails.Qty) AS Qty,
tblPOdetails.Price AS Price
FROM tblPOdetails
JOIN tblPDdetails ON tblPOdetails.PONumber = tblPDdetails.PONumber
WHERE tblPOdetails.PONumber = 12345
编辑:将表名添加到PONumber。
Edit2:将USING
替换为ON
。感谢Hart CO的提示!
答案 1 :(得分:-1)
select tblPOdetails.PONumber,
tblPOdetails.item,
tblPOdetails.qty - tblPDdetails.qty AS qty,
tblPOdetails.price
from tblPOdetails
inner join tblPDdetails on tblPOdetails.PONumber = tblPDdetails.PONumber
where tblPOdetails.PONumber = 12345