这是我的代码,我知道联接不正确。下面的查询为我提供了1985年的12个月的值,但我想查找该特定值的平均值,我不知道如何
WITH samplefordata AS
(
SELECT
ersbusinesslogic_id,
ersbusinesslogic_inputdataseries
FROM
cosd.ersbusinesslogic
WHERE
ersbusinesslogic_formula LIKE '%Avg%'
AND ersbusinesslogic_inputtimedimensionvalue = 'all months'
)
SELECT
cosd.ersbusinesslogic.ersbusinesslogic_id,
AVG(cosd.ersdatavalues.ersdatavalues_attributevalue) AS outputvalue,
cosd.ersbusinesslogic.ersbusinesslogic_outputdestination,
cosd.ersbusinesslogic.ersbusinesslogic_longdesc,
GETDATE(),
cosd.ersbusinesslogic.ersbusinesslogic_outputunitid,
cosd.ersbusinesslogic.ersbusinesslogic_privacyid,
cosd.ersbusinesslogic.ersbusinesslogic_inputsources,
cosd.ersbusinesslogic.ersbusinesslogic_inputsourceid,
cosd.ersbusinesslogic.ersbusinesslogic_outputtimedimensionvalue,
cosd.ersbusinesslogic.ersbusinesslogic_outputtimedimensiontypeid,
cosd.ersbusinesslogic.ersbusinesslogic_outputname,
Concat(cosd.erstimedimension_lu.erstimedimension_year, '-' + '01' + '-' + '01'),
4 AS [ERSConstructedVariable_DataRowLifecyclePhaseID],
cosd.ersbusinesslogic.ersbusinesslogic_outputgeographydimensionid,
cosd.erstimedimension_lu.erstimedimension_id
FROM
cosd.ersdatavalues,
cosd.erstimedimension_lu,
cosd.ersbusinesslogic,
cosd.ersgeographydimension_lu
WHERE
cosd.ersdatavalues.ersdatavalues_erstimedimension_id = cosd.erstimedimension_lu.erstimedimension_id
AND cosd.ersbusinesslogic.ersbusinesslogic_inputgeographydimensionid = cosd.ersgeographydimension_lu.ersgeographydimension_id
AND cosd.ersdatavalues.ersdatavalues_erscommodity_id = 132-- samplefordata.ersbusinesslogic_inputdataseries
AND cosd.ersbusinesslogic.ersbusinesslogic_id =499-- samplefordata.ersbusinesslogic_id
AND cosd.ersbusinesslogic.ersbusinesslogic_inputtimedimensionvalue = 'all months'
AND cosd.erstimedimension_lu.erstimedimension_timedimensiontype_id = 11
AND cosd.ERSTimeDimension_LU.ERSTimeDimension_Year=1985
AND cosd.ersdatavalues.ersdatavalues_ersunit_id = cosd.ersbusinesslogic.ersbusinesslogic_inputunitid
GROUP BY
cosd.ersbusinesslogic.ersbusinesslogic_id,
ersbusinesslogic_outputdestination,
ersbusinesslogic_longdesc,
ersbusinesslogic_outputunitid,
ersbusinesslogic_inputsources,
ersbusinesslogic_inputsourceid,
ersbusinesslogic_outputtimedimensionvalue,
ersbusinesslogic_privacyid,
ersbusinesslogic_outputtimedimensiontypeid,
ersbusinesslogic_outputname,
ersbusinesslogic_outputgeographydimensionid,
erstimedimension_year,
erstimedimension_id
答案 0 :(得分:0)
也GROUP BY cosd.erstimedimension_lu.erstimedimension_year