Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: How can fetch SUM() of all fields in one Query?

I just want somthing like this:

select SUM(*) from `mytable` group by `year`

any suggestion?

(I am using Zend Framework; if you have a suggestion using ZF rather than pure query would be great!)

Update: I have a mass of columns in table and i do not want to write their name down one by one.


No Idea??

like image 799
Alexar Avatar asked Jan 20 '26 01:01

Alexar


1 Answers

SELECT      SUM(column1) + SUM(column2) + SUM(columnN) 
FROM        mytable 
GROUP BY    year
like image 81
Maxem Avatar answered Jan 21 '26 13:01

Maxem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!