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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Group By's displaying zeros

Status
Not open for further replies.

Zak8022

Technical User
Aug 31, 2004
3
0
0
US
First off, I am using Access 2002.

I have a data set, and i am trying to Group By certain demographic files in my db (q59 as Sex1, in this example). Here is the code I have so far:

Code:
select 2 as QID, 1 as RID, "Yes" as QText, count(Q2) as Result,  Avg(Q59) as Sex1
from sheet1
where Q2 = 1
group by q59
union all
select 2 as QID, 2 as RID, "No" as QText, count(q2) as Result, avg(Q59) as sex1
from sheet1
where q2 = 2
group by q59

Now, the reason I have it like this is for reporting purposes, I need to display the results, even if it is a 0. Right now, that returns the data, grouped correctly.... but say for example that there is no result of '2' in group '2'. It will not return any record displaying 0 (since there is nothing to count).

Is there any way I can have this query return zeroes even in my group by? I understant I may not have explained this very well, but any help is appreciated.
 
select 2 as QID, 1 as RID, "Yes" as QText, count(NZ(Q2,0)) as Result
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top