Two sums on same field in same query based on second field criteri

G

Guest

I have a table called 07DATA which has two fields in it: DOLLARSPAID and
DIRECTION. Dollarspaid is clearly a currency field which has multiple dollar
values. Direction is a field which contains either an "I" or an "O".

What I'm trying to do is to create a query with two fields that shows the
total dollars paid for both "O" and "I". I can easily do this by creating
separate queries and then a third query that returns the results but there
must be a way to do this in just one query?

Thanks in advance!
 
G

Guest

SELECT IIf([DIRECTION] = "I",[DollarsPaid],0) As I_Dollars, IIf([DIRECTION] =
"O",[DollarsPaid],0) As O_Dollars FROM 07DATA;
 
M

Marshall Barton

Carpie said:
I have a table called 07DATA which has two fields in it: DOLLARSPAID and
DIRECTION. Dollarspaid is clearly a currency field which has multiple dollar
values. Direction is a field which contains either an "I" or an "O".

What I'm trying to do is to create a query with two fields that shows the
total dollars paid for both "O" and "I". I can easily do this by creating
separate queries and then a third query that returns the results but there
must be a way to do this in just one query?


SELECT Sum(IIf(Direction = "I", DOLLARSPAID, 0)) As TotalI,
Sum(IIf(Direction = "O", DOLLARSPAID, 0)) As TotalO
FROM [07DATA]
 

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