Report Query Question

G

Guest

I'm creating a report that requires to do Sum & Count for the same
record. I wrote this query, which should union the matching columns
into 1. I've done this all the time in SQL Server, but I'm getting
different output from the Access report query.

Select Name, Count(howmany) as col1, Sum(howmuch) as col2, 0 as col3, 0
as col4
from mytable
where status = 'A'
group by name
union all
Select Name, 0 as col1, 0 as col2, Count(howmany) as col3, Sum(howmuch)
as col4
from mytable
where status = 'B'
group by name


The query does not merge records for the same name, but it show 2
records for the same name instead...
 
P

Pat Hartman\(MVP\)

This isn't a situation where you want a union. It is doing exactly as you
asked which is to make a list of all unique rows. You can run two totals
queries and join them on name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top