MySQL query sum number by row

I would like to sum up by row. Any quick way?

Current query:

select t1.name as domain, cast(sum(t2.http_out)/1024/1024/1024 as decimal(8,2)) as HTTP_out_GB, cast(sum(t2.ftp_out)/1024/1024/1024 as decimal(8,2)) as FTP_out_GB, cast(sum(t2.smtp_out)/1024/1024/1024 as decimal(8,2)) as SMTP_out_GB, cast(sum(t2.pop3_imap_out)/1024/1024/1024 as decimal(8,2)) as POP_IMAP_out_GB 

from domains t1 join DomainsTraffic t2 on t1.id = t2.dom_id 

where t2.date BETWEEN '2014-02-01 00:00:00' AND '2014-02-28 23:59:59' 

group by domain;

example:

+--------------------------------+-------------+------------+-------------+-----------------+
| domain                         | HTTP_out_GB | FTP_out_GB | SMTP_out_GB | POP_IMAP_out_GB |
+--------------------------------+-------------+------------+-------------+-----------------+
| abc.com                        |        0.00 |       0.00 |        0.08 |            0.39 |
| def.com                        |        0.00 |       0.00 |        1.84 |            2.45 |
| fgh.com                        |        0.00 |       0.00 |        0.00 |            0.00 |

What is needed:

+--------------------------------+-------------+------------+-------------+-----------------+-----------------+
| domain                         | HTTP_out_GB | FTP_out_GB | SMTP_out_GB | POP_IMAP_out_GB | TOTAL           |
+--------------------------------+-------------+------------+-------------+-----------------+-----------------+
| abc.com                        |        0.00 |       0.00 |        0.08 |            0.39 | 0.47             
| def.com                        |        0.00 |       0.00 |        1.84 |            2.45 | 4.29             
| fgh.com                        |        0.00 |       0.00 |        0.00 |            0.00 | 0.00             

Answers


select domain, HTTP_out_GB, FTP_out_GB, SMTP_out_GB, POP_IMAP_out_GB,
(HTTP_out_GBFTP_out_GB + SMTP_out_GB + POP_IMAP_out_GB) as total from(
select t1.name as domain, cast(sum(t2.http_out)/1024/1024/1024 as decimal(8,2)) as HTTP_out_GB, cast(sum(t2.ftp_out)/1024/1024/1024 as decimal(8,2)) as FTP_out_GB, cast(sum(t2.smtp_out)/1024/1024/1024 as decimal(8,2)) as SMTP_out_GB, cast(sum(t2.pop3_imap_out)/1024/1024/1024 as decimal(8,2)) as POP_IMAP_out_GB 
from domains t1 join DomainsTraffic t2 on t1.id = t2.dom_id 
where t2.date BETWEEN '2014-02-01 00:00:00' AND '2014-02-28 23:59:59' 
group by domain) as A 

Need Your Help

Maven2 sharing dependencies across parent and children (without redeclaring dependencies in children)

maven-2 dependencies dependency-management

With maven1 I was using the extend tag to tell my children project to use their parent configuration.

Which is better, setEnabled or setUserInteractionEnabled?

ios objective-c uibutton setuserinteractionenabled

I want to make a UIButton disable for user touch. Both setEnabled and setUserInteractionEnabled can do this. Which is better? How are they different?