db2 query with sum in condition
Posted on 2006-07-13
I'm running a query and I have had some success so far, BUT that run of success has ended when I added my last condition.
What I am looking to do is getting the total spend by a customer during the year 2005 but only if the total that customer spent was 1500.
SELECT SUM(INVOPR) FROM INHEAD WHERE CUST = 'BLAHBLAH' AND year(IHDATE) = 2005 AND SUM(INVOPR)<=1500
SELECT SUM(INVOPR) FROM INHEAD WHERE CUST = 'BLAHBLAH' AND year(IHDATE) = 2006 AND SUM(INVOPR)<=1500
This is via ODBC, sum works to get the $$$ out, but when I use it as a condition I think that is where it is bombing.