3569 Improper use of an aggregate function in WHERE Clause

General
General covers Articles, Reference documentation, FAQs, Downloads and Blogs that do not belong to a specific subject area. General-purpose Articles about everything and anything
Enthusiast

3569 Improper use of an aggregate function in WHERE Clause

Hello All,

I am running a very simple query where I want to aggregate certain attributes for a 12 month window based on invoice date, however when I tried running this , it throws me the "3569 Improper use of an aggregate function in  WHERE Clause " which needs HAVING clause. Can someone help me as I have to have a running 12 month window for the same 

 

SELECT
SUM(local_net_rev_amt),
SUM(local_fgt_amt),
SUM(local_fuel_schg_amt),
SUM(tot_local_sphnd_rev_amt),
SUM(local_rbte_rev_amt),
SUM(loc_disc_rev_amt),
SUM(shp_pc_qty),
SUM(shp_qty)
entr_typ_cd,
shp_cntry_cd,

FROM databse.tnt_invoice_detail
WHERE inv_dt BETWEEN ADD_MONTHS (DATE, -12) AND DATE
AND entr_typ_cd = 'FR'
GROUP BY
entr_typ_cd,
shp_cntry_cd

1 REPLY
Teradata Employee

Re: 3569 Improper use of an aggregate function in WHERE Clause

You are missing a comma after the last SUM.