朋友, 下面的SQL如果不带INSERT部分执行;显示预期的记录。 但是,当用INSERT部分执行时,会导致SQL错误:“ ORA-00979:不是GROUP BY表达式”。
字段名称“ weekly_pro_sales_52wks”(别名为value32)是源中的新字段。它是使用alter table添加到现有表中的新字段。而且,如果我使用旧字段代替新字段,则INSERT操作成功,但是使用新字段名则为Error。
如果我在这里缺少任何步骤,请帮助我。
INSERT /*+ APPEND PARALLEL(8) */
INTO tmp_pog_summary_tbl
(
pog_key,
prd_key,
Value32
)
WITH avg_invnt AS
(
SELECT stg.Store, stg.ID,
max(stg.Weekdate) weekdate,
max(stg.AVGINVENTORYUNITS_PREVWEEK) AVGINVENTORYUNITS_PREVWEEK,
max(stg.AVGINVENTORYPESOS_PREVWEEK) AVGINVENTORYPESOS_PREVWEEK
FROM CSG_SALES_DATA_STG stg
JOIN (
SELECT stg3.store,
stg3.ID,
MAX(stg3.WEEKDATE) Maxweekdate
FROM CSG_SALES_DATA_STG stg3
WHERE stg3.store in (1161, 1162,1163)
GROUP BY store, id
) stg2
ON (stg.Store = stg2.Store AND stg.ID = stg2.ID AND stg.WEEKDATE = stg2.Maxweekdate)
JOIN CSG_CALENDAR_STG cal ON (cal.WDATE=stg.WEEKDATE)
WHERE cal.DAYWEEK=1 AND stg.store in (1161, 1162,1163)
GROUP BY stg.Store, stg.ID
)
SELECT /*+ FULL(POS) PARALLEL(POS,8) */
pog.DbKey,
prd.DbKey,
nvl(SUM(pos.weekly_pro_sales_52wks),0) Value32
FROM csg_sales_aggregate_stg pos
JOIN ix_str_store str ON pos.str_dbkey = str.DBKey
JOIN ix_str_store_floorplan strflr ON str.DbKey = strflr.DbParentStoreKey
JOIN ix_flr_floorplan flr ON strflr.DBParentFloorplankey = flr.DbKey
JOIN ix_flr_performance flrperf ON flr.DbKey = flrperf.DBParentFloorplankey
JOIN ix_spc_planogram pog ON flrperf.DbParentPlanogramKey = pog.Dbversionkey
JOIN ix_spc_performance perf ON (perf.DBParentPlanogramKey = pog.DBkey)
JOIN ix_spc_product prd ON perf.DBParentProductKey = prd.DbKey
JOIN avg_invnt tmp ON (tmp.Store = pos.StoreNumber AND tmp.ID = pos.PRODUCT_ID)
WHERE prd.DbKey = pos.prd_dbkey
AND pog.DBStatus in (1,2)
AND perf.facings>0
And str.storenumber in (1161, 1162,1163)
AND flr.DBStatus IN (1,2)
AND flrperf.numberofsections>0
GROUP BY pog.DBKey, prd.DbKey;