Andy Trezise
2010-05-26 23:04:19 UTC
I want to select all customers from a SQL table along with a sum of all
their invoices but I'm having trouble using the where / group by clause
My statement reads
SQLEXEC(nSQL,"SELECT t1.*,SUM(t2.total_amount) AS total FROM CUSTOMERS as t1
left join invoices AS t2 ON (t1.account_code=t2.account_code) group by
t1.account_code","MY_RECS")
This works OK but as soon as I add a WHERE clause it fails...
SQLEXEC(nSQL,"SELECT t1.*,SUM(t2.total_amount) AS total FROM CUSTOMERS as t1
left join invoices AS t2 ON (t1.account_code=t2.account_code) group by
t1.account_code WHERE total > 1000","MY_RECS")
I've tried rearranging the statement but nothing seems to work.
their invoices but I'm having trouble using the where / group by clause
My statement reads
SQLEXEC(nSQL,"SELECT t1.*,SUM(t2.total_amount) AS total FROM CUSTOMERS as t1
left join invoices AS t2 ON (t1.account_code=t2.account_code) group by
t1.account_code","MY_RECS")
This works OK but as soon as I add a WHERE clause it fails...
SQLEXEC(nSQL,"SELECT t1.*,SUM(t2.total_amount) AS total FROM CUSTOMERS as t1
left join invoices AS t2 ON (t1.account_code=t2.account_code) group by
t1.account_code WHERE total > 1000","MY_RECS")
I've tried rearranging the statement but nothing seems to work.