View Full Version : Combine Two Select Statements


crhodus
11-13-2001, 10:48 AM
I have written the following two queries:

SELECT comaster.county, AVG(comaster.hour_rate) as avgrate, COUNT(comaster.co_number) as sumzero
WHERE comaster.hour_rate > 0
FROM comaster
GROUP BY comaster.county
ORDER BY comaster.county


SELECT COUNT(comaster.co_number) as sumall
FROM comaster
GROUP BY comaster.county
ORDER BY comaster.county

The first query selects all the records that have an hourly rate that is greater than zero and returns the average hourly rate, the number of companies in the county that have an hourly rate greater than zero, and the county name.

The second query counts the total number of records in the database. How do I combine both queries so that the query returns :
all the records that have an hourly rate that is greater than zero and returns the average hourly rate, number of companies in a county with hourly rates greater than zero, the county name PLUS the total number of companies in that county (regardless if the hourly rate is > 0 or not)?

Please let me know if I need to clarify.

Thanks!


[This message has been edited by crhodus (edited 11-13-2001).]

[This message has been edited by crhodus (edited 11-13-2001).]

Pat Hartman
11-13-2001, 04:55 PM
The domains for the two counts are not the same. Therefore, they cannot be done in a single query. If you want to combine the two queries that you currently have so that all the counts end up in a single recordset, create a new query that joins the the two totals queries on country.