Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

doing more math in a query

Status
Not open for further replies.

sysadmin42

Technical User
May 6, 2005
138
Hi. here's the code:
Code:
$result=doQuery("SELECT high_estimate,low_estimate FROM projects WHERE status IN (SELECT id FROM project_status WHERE name LIKE '%In Progress%')");
while ($line=mysql_fetch_assoc($result)) { 
  $high+=$line['high_estimate']; 
  $low+=$line['low_estimate']; 
}

This gives me exactly what I want: the sums of 'high_estimate' and 'low_estimate' for items that match the subquery.

Is there a way to get all that into the query? or at the very least simplify my PHP?

The first thing I tried was:
Code:
SELECT SUM(high_estimate) AS high_estimate FROM projects WHERE status IN (SELECT id FROM project_status WHERE name LIKE '%In Progress%');
but it kept giving me errors. Any thoughts?
 
well, I just tried the query again and although it didn't work right, it also didn't give me any errors.

but my real question is: Is there any way to simplify the first block of code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top