Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Select Failed: 3504: Selected non_aggregate values must be part of the associated group - response (1) by msk.khurram

$
0
0

In fact you are using aggregate function in you query and forgot to use group by clause for non aggregate columns.
for example for the following part of your query the group by is missing:

-- ****************************************************** ******************

INNER JOIN (SELECT

ALL_MEMBER.MEDICAID_NBR AS Member_Nbr,

Count(DIM_DRUG.GPI_NBR||PHARMACY_FILL_DATE.DATE_DATE) AS Member_Drug_Count

FROM

DIM_MEMBER ALL_MEMBER

INNER JOIN DIM_MEMBER_ELIGIBILITY MEMBER_ELIGIBILITY ON (MEMBER_ELIGIBILITY.EDW_MEMBER_CK=ALL_MEMBER.EDW_MEMBE R_CK

AND MEMBER_ELIGIBILITY.PLAN_DIM_CK=ALL_MEMBER.PLAN_DIM_CK) 

INNER JOIN FT_PHARMACY_CLAIM ON (MEMBER_ELIGIBILITY.MEMBER_ELIGIBILITY_CK=FT_PHARMACY_ CLAIM.SUBSCRIBER_MEMBER_ELIG_DIM_CK)

INNER JOIN DIM_DRUG ON (FT_PHARMACY_CLAIM.DRUG_DIM_CK=DIM_DRUG.DRUG_DIM_CK)

INNER JOIN DIM_DATE PHARMACY_FILL_DATE ON (PHARMACY_FILL_DATE.DATE_DIM_CK=FT_PHARMACY_CLAIM.FILL _DATE_DIM_CK)

INNER JOIN dim_date birth_date ON all_member.birth_date_dim_ck = birth_date.date_dim_ck

INNER JOIN ( SELECT

COMPLIANCE_OWN.KY_PYSCH_DRUG.DOSAGE,

COMPLIANCE_OWN.KY_PYSCH_DRUG.DRUG_NAME,

COMPLIANCE_OWN.KY_PYSCH_DRUG.GPI,

COMPLIANCE_OWN.KY_PYSCH_DRUG.GCN,

COMPLIANCE_OWN.KY_PYSCH_DRUG.KTYCLASS,

COMPLIANCE_OWN.KY_PYSCH_DRUG.STRENGTH

FROM

COMPLIANCE_OWN.KY_PYSCH_DRUG

WHERE COMPLIANCE_OWN.KY_PYSCH_DRUG.KTYCLASS = 'ANTI-PSYCHOTICS: ATYPICALS' ) PYSCH_DRUG ON PYSCH_DRUG.GPI=DIM_DRUG.GPI_NBR

 GROUP BY 1 --This group by was missing

WHERE

 

FT_PHARMACY_CLAIM.PLAN_DIM_CK IN (5,16)

AND

ALL_MEMBER.PLAN_DIM_CK IN (5,16)

AND

PHARMACY_FILL_DATE.DATE_DATE BETWEEN TRUNC(ADD_MONTHS(CURRENT_DATE,-12),'Q') AND trunc(Current_Date,'Q')-1

AND

REVERSAL_IND = 'N') MEMBER_DRUG_COUNT

 

Secondly you have used group by at the end of query for 6 columns, but you are selecting 8 columns with out any aggregate function, Now you have to use group by 1,2,3,4,5,6,7,8 OR if it is not required then ommit it.  

 

Hope this will work for you!

 

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>