我正在尝试创建一个子查询以将两个表放在一起,但什么也没得到。
代码:
SELECT DISTINCT Agreements.AgrmntID, Agreements.Status, JobSites.SiteName,
PurchaseOrderDetails.ExtCost
FROM Agreements Inner Join
JobSites On Agreements.CustSiteID = JobSites.CustSiteID
WHERE Agreements.Status = 2 And PurchaseOrderDetails.ExtCost = (Select
PurchaseOrderDetails.ExtCost
FROM PurchaseOrderDetails
Inner Join PurchaseOrders On PurchaseOrders.POID = PurchaseOrderDetails.POID
WHERE PurchaseOrders.Description Like ('%', JobSites.SiteName, '%') And
Convert(varchar(8),PurchaseOrderDetails.TimeCreated,1) = '09/10/12')
ORDER BY JobSites.SiteName
预期输出:
AgreemntID Status SiteName ExtCost
----------------------------------------
1 2 TEST01 $144.00
2 2 TEST02 $400.00
我正在使用子查询,因为除了 PurchaseOrders 下的描述之外,没有任何东西可以将 ExtCost 链接到 SiteName。
希望这是足够的信息,可以帮助我。先感谢您!!