I have a database which print me all employees of countries.
|Year|Country1|Country2|Country3|Country4|All
This is table, only with 25 countries and year from 2000 to now. In Internet I found only information for sum(country4) for example, but how can use sum with all fields exclude Year and All.
Updated:
Year | ZA | NA | BW | MG | ZW | AO | ZM | KE | NG | CF | GH | CM | CD | ET | UG | EG | DZ | MA | MR | NE | SD | TN | SO | All
------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-----
2000 | 10 | 10 | 5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 25
2001 | 25 | 10 | 8 | 5 | 5 | 9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 62
This is database and I need the sum from ZA to SO without year
and All
. All
is the result of the sum, but I think SQLite or PHP can build sum without me doing it manually?
When I search in internet I found only example for sum of one column but not for rows.
To 'sum a row' you simply add the relevant fields together:
select
ZA+NA+BW+MG+ZW+AO+ZM+KE+NG+CF+GH+CM+CD+ET+UG+EG+DZ+MA+MR+NE+SD+TN+SO
from
table_name
That results in (from your test data) two rows:
25
62
If you want to get the sum of those values just wrap the addition in a sum
:
sum(ZA+NA+BW+MG+ZW+AO+ZM+KE+NG+CF+GH+CM+CD+ET+UG+EG+DZ+MA+MR+NE+SD+TN+SO)
Result:
87
|Year|ZA|NA|BW|MG|ZW|AO|ZM|KE|NG|CF|GH|CM|CD|ET|UG|EG|DZ|MA|MR|NE|SD|TN|SO|All|
|2000|10|10|5|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|25|
|2001|25|10|8|5|5|9|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|62|
This is database and I need the sum from ZA to SO without year and All. All is the result of the sum, but i think sqlite or php can build sum without I do it manually or?
When I search in internet i found only example for sum of one column but not for rows.
Thank you
Silvio