Sandi Budic Sandi Budic - 1 month ago 5
MySQL Question

how to sum multiple columns into one result from database in php? is that posible?

i have big database table and i need result from multiple columns into one. its about how much people is checked from some conturies and every contry has own column. here is some of it:

rs_turista
,
rs_nocenja
,
agencija_turista
,
agencija_nocenja
,
at_turista
,
at_nocenja
,
be_turista
,
be_nocenja
,
ba_turista
...
they is checking every day. i need to sum it all in php for report. is that posible?

Answer

Don't do it in PHP, that's needlessly selecting too much data from a database. All you gotta do is use a SUM() and + like so:

SELECT SUM(column1) + SUM(column2) + SUM(column3) + ... AS total
FROM table
WHERE <filters for a date or other requirements>
Comments