I have a table with the following contents:
| Country | Username |
+ --------------- + ---------------- +
| US | John |
| IT | Pedro |
| US | Bob |
| FR | Jill |
| 192.168.1.2 | Roupraht |
| 192.168.1.20 | Antonio |
+ --------------- + ---------------- +
I want to calculate the users of each country, and users with an IP address instead of a country should be considered "unknown";
I was able to write the following SQL query:
select country, count(*) as total from users group by country;
And I got the following result:
+ ----------------- + ------- +
| country | total |
+ ----------------- + ------- +
| 192.168.1.2 | 1 |
| 192.168.1.20 | 1 |
| US | 2 |
| IT | 1 |
| FR | 1 |
+ ----------------- + ------- +
How can I count all IP addresses as "unknown"?
my goal is to get the table as follows:
+ ----------------- + ------- +
| country | total |
+ ----------------- + ------- +
| Unknown | 2 |
| US | 2 |
| IT | 1 |
| FR | 1 |
+ ----------------- + ------- +
Zibar source share