我想弄清楚如何將這3個查詢合併爲一個百分比列,我還沒有弄清楚。任何人都可以協助SQL查詢修改/優化
Select DISTINCT a.ASSN As Association, SUM(tonnage_adjusted) as TotalTonnage
From DeliveryTons d INNER JOIN ReapingGroups a ON d.reaping_code = a.REAPING_GROUP_CODE
WHERE reaping_code IS NOT NULL
Group By a.ASSN
ORDER BY Association
Select DISTINCT a.ASSN As Association, SUM(tonnage_adjusted) as Monitored
From DeliveryTons d INNER JOIN ReapingGroups a ON d.reaping_code = a.REAPING_GROUP_CODE
WHERE remarks = '' AND reaping_code IS NOT NULL
Group By a.ASSN
ORDER BY Association
Select DISTINCT a.ASSN As Association, SUM(tonnage_adjusted) as NotMonitored
From DeliveryTons d INNER JOIN ReapingGroups a ON d.reaping_code = a.REAPING_GROUP_CODE
WHERE remarks = 'NO_TICKET' AND reaping_code IS NOT NULL
Group By a.ASSN
ORDER BY Association
百分比列的公式是什麼?另外,你使用的是什麼版本的SQL服務器? – Sparrow
它應該是什麼監視除以totaltonnage時間100. im使用Microsoft SQL Server 2008 – ivias