sql - How to get the totals of each column MySQL -


i have sql query number of jobs, gross weight etc different companies.

the result in mysql workbench looks this: enter image description here

i add row @ bottom calculates total of each column i.e total of jobs column 267. how add row totals?

sql query:

select             c.name,             count(distinct jn.id) jobs,             sum(jn.actualweight) grosswt,             sum(jpc.advisedqty) units_in,             sum(jpd.advisedqty) units_out             customer c         left join job_new jn on jn.jobownerid = c.id         left join job_pieces jp on jp.jobid = jn.id         left join job_pieces jpc on jpc.jobid = jn.id , jn.collectmemberid = jn.jobownerid         left join job_pieces jpd on jpd.jobid = jn.id , jn.delivermemberid = jn.jobownerid    jn.isactive = 1 group jn.jobownerid 

you looking group by modifier with rollup:

select c.name,        count(distinct jn.id) jobs,        sum(jn.actualweight) grosswt,        sum(jpc.advisedqty) units_in,        sum(jpd.advisedqty) units_out customer c left join      job_new jn      on jn.jobownerid = c.id left join      job_pieces jp      on jp.jobid = jn.id left join       job_pieces jpc      on jpc.jobid = jn.id , jn.collectmemberid = jn.jobownerid left join      job_pieces jpd      on jpd.jobid = jn.id , jn.delivermemberid = jn.jobownerid jn.isactive = 1 group c.name rollup; 

note: changed group by key 2 reasons. first, should match column used in select. second, using value left joined table, value null. undesirable.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -