Marikit Avendano Marikit Avendano - 1 year ago 60
MySQL Question

Get total value of the same column multiple rows and total of two different rows (mysql query)

I have a table "records"

select typeofservice,
Coalesce(sum(incomecost,expensecost),0) 'incomecost,expensecost'
from records
where dateoftrans = '2016-11-22'
group by typeofservice with rollup;

I want to be able to have the result on the second image and this is my query... and all of this transactions happened on one day. Please help

Answer Source

If only for second image's result, you can try sum(incomecost) and sum(expensecost) like this:

    Coalesce(SUM(incomecost), 0) AS incomecost,
    Coalesce(SUM(expensecost), 0) AS expensecost
FROM records
GROUP BY typeofservice
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download