Shamrox Posted November 20, 2007 Share Posted November 20, 2007 I've got this query that I need a little tweaking done to. SELECT `spec_vendorinfo`.Company_Name as name,`spec_registrar`.vendorid as vendorid, SUM(`spec_registrar`.cogs) as totalcogs FROM `spec_registrar`, `spec_vendorinfo` WHERE `spec_vendorinfo`.vid = `spec_registrar`.vendorid and `spec_registrar`.orderdate >= '2007-01-01' and `spec_registrar`.orderdate <= '2007-11-01' and totalcogs >= 10000 GROUP BY `spec_registrar`.vendorid If you see the use of SUM on the cogs field and calling it as totalcogs. I want to be able to specify in the WHERE section that I only want results of totalcogs over 10,000. The way i have it written doesn't work. How would I adjust the query to use this totalcogs? Link to comment https://forums.phpfreaks.com/topic/78134-query-help/ Share on other sites More sharing options...
fenway Posted November 20, 2007 Share Posted November 20, 2007 You need to use HAVING totalcogs>10000 -- you can't check the result of aggregate functions in the WHERE clause. Link to comment https://forums.phpfreaks.com/topic/78134-query-help/#findComment-395460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.