ऐसा लगता है कि, एक एकत्रीकरण क्वेरी की जरूरत के बजाय इस परिसर में एक के। जैसे
select companyName, assetName, year,
Sum(DatapointValue) as MPPOilRevised
from PEBaseQuery
where DatapointID in (2032, 2034, 2042, 2036)
group by companyName, assetName, year
एकमात्र मुद्दा पहले डेटा प्वाइंट के लिए 1000000 गुणा कर रहा है। आपको लगता है कि के लिए IIF
की कोशिश कर सकते:
select companyName, assetName, year,
Sum(IIf(DatapointID=2003,DatapointValue*1000000,DatapointValue)) as MPPOilRevised
from PEBaseQuery
where DatapointID in (2032, 2034, 2042, 2036)
group by companyName, assetName, year
इसके अलावा इस तरह के 'पागल' क्वेरी, उप क्वेरी के साथ इस विशेष DatapointID के लिए, IIF
बिना प्रयास करें: के लिए 'उत्पादन अधिकतम संभावित'
select companyName, assetName, year, SUM(DatapointValue)
+ (select SUM(DatapointValue * 1000000) from PEBaseQuery q2
where q2.companyName = q1.companyName
and q2.assetName= q1.assetName
and q2.year= q1.year
and q2.DatapointID = 2003
group by companyName, assetName, year)
from PEBaseQuery q1
where DatapointID in (2032, 2034, 2042, 2036)
group by companyName, assetName, year
अद्यतन। कृपया निम्नलिखित का प्रयास करें:
select b.companyName, b.assetName, IIf(b.calculationResult > mp.calculationResult,b.calculationResult,mp.calculationResult) as MPPOilRevised
from
(select companyName, assetName, year, Sum(IIf(DatapointID=2003,DatapointValue*1000000,DatapointValue)) as calculationResult
from PEBaseQuery
where DatapointID in (2032, 2034, 2042, 2036)
group by companyName, assetName, year) b --Base
left join
(select companyName, assetName, year,
Sum(DatapointValue) as calculationResult
from PEBaseQuery
where DatapointID = 2218
group by companyName, assetName, year) mp -- Max Potential
on b.companyName= mp.companyName
and b.assetName = mp.assetName
and b.year = mp.year
substract तर्क के साथ गणना का उदाहरण। अंतिम पागल एसक्यूएल के साथ अपडेट किया गया। कृपया ध्यान दें कि मैं चीजों को इस तरह के लिए आवेदन तर्क या संग्रहित प्रक्रियाओं के साथ जाना होगा:
select b.companyName, b.assetName, IIf(b.calculationResult > mp.calculationResult,b.calculationResult,mp.calculationResult) as MPPOilRevised
from
(select companyName, assetName, year, SUM(DatapointValue)
+ (select SUM(DatapointValue * 1000000) from PEBaseQuery q2
where q2.companyName = q1.companyName
and q2.assetName= q1.assetName
and q2.year= q1.year
and q2.DatapointID = 2003
group by companyName, assetName, year)
- (select SUM(DatapointValue) from PEBaseQuery q2
where q2.companyName = q1.companyName
and q2.assetName= q1.assetName
and q2.year= q1.year
and q2.DatapointID = 2029
group by companyName, assetName, year)
from PEBaseQuery q1
where DatapointID in (2032, 2034, 2042, 2036)
group by companyName, assetName, year) b --Base
left join
(select companyName, assetName, year,
Sum(DatapointValue) as calculationResult
from PEBaseQuery
where DatapointID = 2218
group by companyName, assetName, year) mp -- Max Potential
on b.companyName= mp.companyName
and b.assetName = mp.assetName
and b.year = mp.year
'' में qbX.DatapointValue' ऑपरेंड बाहर सपाट प्रयास करें (से ... कहां qbX.DatapointValue का चयन करें ... ।) एएस एक्सप्रैक्स'। – EthanB
कुछ अलग सवाल .. आपको पहले DatapointValue के लिए 1000000 पर गुणा करने की आवश्यकता क्यों है? यह बहुत अजीब लग रहा है, क्योंकि मान एक कॉलम से हैं। मुझे लगता है कि पूरी क्वेरी को इसके बिना और अधिक सरल बनाने का तरीका है। – udalmik
एक लाख से गुणा करने के कारण है क्योंकि मुझे प्रति मिलियन बैरल तेल – Magda