0

我有一个由于错误 SQL 错误而失败的 sql 查询:ORA-00979: not a GROUP BY expression 这里是:

select * from (
                select 
                    ob.offer_bank_id
                    , ob.promo_period_id
                    , ob.offer_bank_nm
                    , obst.offer_bank_status_type_dsc
                    , ob.effective_start_dt
                    , ob.effective_end_dt
                    , obt.offer_bank_type_dsc
                    , obt.offer_bank_type_cd
                    , pp.promo_period_nm
                    , SUM(CASE WHEN a.offer_id IS NOT NULL THEN 1 ELSE 0 END) as total_count
                    , SUM(CASE WHEN a.offer_status_type_cd = 'ED' THEN 1 ELSE 0 END) as editing_count
                    , SUM(CASE WHEN a.offer_status_type_cd = 'FD' THEN 1 ELSE 0 END) as failed_deactive_count
                    , SUM(CASE WHEN a.offer_status_type_cd in ('FP', 'FI') THEN 1 ELSE 0 END) as failed_production_co
                    , SUM(CASE WHEN a.offer_status_type_cd = 'FV' THEN 1 ELSE 0 END) as failed_preview_count
                    , SUM(CASE WHEN a.offer_status_type_cd = 'LD' THEN 1 ELSE 0 END) as loaded_count                 
                    , SUM(CASE WHEN a.offer_status_type_cd in ('PE', 'PS') THEN 1 ELSE 0 END) as pending_count
                    , SUM(CASE WHEN a.offer_status_type_cd = 'PK' THEN 1 ELSE 0 END) as parked_count
                    , SUM(CASE WHEN a.offer_status_type_cd = 'SD' THEN 1 ELSE 0 END) as successfully_deactivated_count
                    , SUM(CASE WHEN a.offer_status_type_cd in ('SP','PI') THEN 1 ELSE 0 END) as successfully_loaded_to_prod
                    , SUM(CASE WHEN a.offer_status_type_cd = 'SV' THEN 1 ELSE 0 END) as successfully_loaded_to_preview          
                    , SUM(CASE WHEN a.offer_status_type_cd in ('LD','PE','PS') THEN 1 ELSE 0 END) as total_pending_count        
                    , SUM(CASE WHEN a.offer_status_type_cd in ('FD','FP','FV','FR','FI') THEN 1 ELSE 0 END) as failed_count
                    , COUNT(1) OVER(PARTITION BY 1) as total_rows
                    , ROW_NUMBER() OVER (ORDER BY ob.effective_end_dt desc) as row_nbr   
                    , MAX(a.offer_effective_end_dt) as max_offer_effective_end_dt
                    , MIN(a.offer_effective_start_dt) as min_offer_effective_start_dt
                    , SUM(CASE WHEN a.offer_status_type_cd in ('AR','SR','SD') THEN 1 ELSE 0 END) as ended_count  
                    , SUM(CASE WHEN a.offer_status_type_cd in ('CD') THEN 1 ELSE 0 END) as copient_delay_count
                    , SUM(CASE WHEN a.offer_status_type_cd in ('SR') THEN 1 ELSE 0 END) as rejected_count
                    , SUM(CASE WHEN a.offer_status_type_cd in ('LV', 'GV', 'CD', 'GA', 'GC', 'GD', 'GI', 'GP', 'GR', 'LA', 'LI', 'LP', 'LR', 'LV', 'LE')
                        THEN 1 ELSE 0 END) as processing_count
                    , a.store_banner_cd
                    , a.banner_nm
                from 
                    offer_bank ob
                    INNER JOIN offer_bank_status obs
                    ON ob.offer_bank_id = obs.offer_bank_id
                    INNER JOIN offer_bank_status_type obst
                    ON obs.offer_bank_status_type_cd = obst.offer_bank_status_type_cd
                    INNER JOIN promo_period pp
                    ON ob.promo_period_id = pp.promo_period_id
                    INNER JOIN offer_bank_type obt
                    ON ob.offer_bank_type_cd = obt.offer_bank_type_cd               
                    LEFT OUTER JOIN 
                        (select 
                            o.offer_id
                            , o.offer_bank_id
                            , sb.store_banner_cd
                            , sb.banner_nm
                            , ost.offer_status_type_cd
                            , o.offer_effective_end_dt
                            , o.offer_effective_start_dt
                         from 
                            offer o
                            INNER JOIN offer_store_banner osb
                            ON o.offer_id = osb.offer_id
                            INNER JOIN store_banner sb
                            ON osb.store_banner_cd = sb.store_banner_cd
                            INNER JOIN offer_status os
                            ON o.offer_id = os.offer_id
                            INNER JOIN offer_status_type ost
                            ON os.offer_status_type_cd = ost.offer_status_type_cd
                            AND os.effective_end_dt is null
                        ) a
                    ON ob.offer_bank_id = a.offer_bank_id
                where
                    obs.effective_end_dt is null

             group by
                            ob.offer_bank_id
                            , ob.promo_period_id
                            , ob.offer_bank_nm
                            , obst.offer_bank_status_type_dsc
                            , ob.effective_start_dt
                            , ob.effective_end_dt
                            , obs.effective_start_dt
                            , ob.creation_ts
                            , obt.offer_bank_type_dsc
                            , obt.offer_bank_type_cd
                            , obst.offer_bank_status_type_cd
                            , pp.promo_period_nm
                        order by
                            ob.effective_end_dt desc
                    ) a
                        where
                            a.row_nbr > 0;

我知道 group by 子句中有问题。只是似乎没有得出结论。任何帮助表示赞赏

4

1 回答 1

2

你错过了a.store_banner_cdand a.banner_nminGROUP BY子句。

出现在SELECT中且未聚合的所有列也必须在 中找到GROUP BY

于 2013-07-20T08:23:47.780 回答