SQL Query在WHERE Exist CLAUSE中包含第三列

时间:2017-03-14 03:42:36

标签: sql

如何将SUM(tonnage_adjusted)DeliverTons列的SELECT DISTINCT CROP_CLASS As Opened,SUM(ACREAGE) AS SumofAcreage From CaneParcel WHERE EXISTS (SELECT * FROM DeliveryTons WHERE CaneParcel.FIELD_ID = DeliveryTons.parcel_id AND parcel_status = 1) Group By CROP_CLASS Order By SumofAcreage DESC 包含到此SQL查询中以生成我需要的3列值。

{{1}}

1 个答案:

答案 0 :(得分:2)

希望这能解决您的问题

SELECT  
CROP_CLASS As Opened,
SUM(ACREAGE) AS SumofAcreage,
SUM(tonnage_adjusted) AS TonnageAdjusted
FROM 
CaneParcel
INNER JOIN DeliveryTons ON CaneParcel.FIELD_ID = DeliveryTons.parcel_id AND parcel_status = 1
Group By CROP_CLASS
Order By SumofAcreage