MySQL count/sum fields

Posted by Conor H on Stack Overflow See other posts from Stack Overflow or by Conor H
Published on 2010-05-02T12:38:38Z Indexed on 2010/05/02 12:47 UTC
Read the original article Hit count: 169

Filed under:
|
|

Hi There,

What I am trying to achieve is a report on daily financial transactions. With my SQL query I would like to count the total number of cash transactions, the total cash value and the same for checks. I only want to do this for a specified date.

Here is a snippet of the query that I am having trouble with. These sum and count commands are processing all the data in the table and not for the selected date.

(SELECT SUM(amount) FROM TRANSACTION WHERE payment_type.name = 'cash') AS total_cash,
(SELECT COUNT(*) FROM TRANSACTION WHERE payment_type.name = 'cash') AS total_cash_transactions

Sorry if I havent posted enough detail as I haven't time. If you need more info just ask..

Cheers.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about count