Hello all again. I have run into a tough spot when using SUM. Here is what I am working with :
mysql_query("SELECT id, owner, thetime, SUM(totalorder + tax) AS ordertotal FROM workorders AS w WHERE ordertotal >= (SELECT SUM(amount) FROM payments WHERE id=w.id)") or die(mysql_error());
What I am attempting to do is get selective information from "workorders" where total paid (amount) in "payments" are greater than or equal to the SUM of "workorders" totalorder and tax.
Currently I am getting this error : Unknown column 'ordertotal' in 'where clause'
If I change the query to this :
mysql_query("SELECT id, owner, thetime AS ordertotal FROM workorders AS w WHERE SUM(w.totalorder + w.tax) >= (SELECT SUM(amount) FROM payments WHERE id=w.id)") or die(mysql_error());
I get this error : Invalid use of group function
Any help on how I can get this done successfully?