I want to query and output a count of countries where residents of each country last travelled to. I have the following query:
SELECT
COUNTRY, SUM(COUNTRY_OF_LAST_TRAVEL = 'USA') AS USA
FROM BASE_TABLE
GROUP BY
COUNTRY
and the output is something like this:
Country | USA
--------- ------
Argentina | 0
Australia | 293
Bahrain | 1
....
115 more rows
Let's say I have a table with 3 columns - ID, Country_of_residence, and Country_of_last_travel - It's mostly country data where each ID# corresponds to that member's country of residence, and where they last travel to. How do I output all other country as column so I can output the count? I've tried looking into loops but I'm not getting anywhere with it. Thank you!
Expected result:
Country | USA | Japan | Country n |
--------- ------ --------
Argentina | 0 | 25 | 0 |
Australia | 293 | 0 | 12 |
Bahrain | 1 | 10 | 351 |
....
115 more rows
I'm using DBBrowser for SQLite.