sql - Mysql query for sum based off a value in a column group by that column -


i mysql newbie here need sql query cant quite figure out.

i have table transact contains this:

paytype amount  date cash    100.0   2013-08-01 visa    50.00   2013-09-2 check   50.00   2013-11-12 cash    75.00   2013-12-01 cash    50.00   2013-12-19 visa    100.00  2014-3-01 cash    20.00   2014-5-20 

amount , pay type ordered based on transaction dates, want queried out table gives sum of amount each paytype , grouped paytype this:

paytype total cash    245.00 visa    100.00 check   50.00 

having based off date range want based 2013-12-15 2014-5-01. can out 1 single sum specific paytype

select paytype, (sum(if(paytype = 'cash', amount, 0)) transact group paytype. 

please proper query execute that! much!

you can basic group by , sum query:

select  paytype, sum(amount) total    transact   date between '2013-12-15' , '2014-05-01' group paytype 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -