SQL: Sum Multiple Records in One Table

Something I cannot seem to memorize, how to sum multiple records in one table based on another field using SQL. For example:


Country    Visitors
-------------------
USA        140
Japan      50
USA        99
Japan      75

If you want to sum up the visitors based on country, then the following SQL-statement should do the trick:

select Country, sum(Visitors) as Visits from countries_combined_001 group by Country order by Visits desc;

Again, really obvious, in theory. 😉

Post a Comment

Your email is never published nor shared. Required fields are marked *, comments are moderated.

*
*