I need to use MySQL to find how many rivers are only in one country. Basically counting the numbers that are never duplicated
riverID Country
1 BI
1 CD
1 EG
1 ER
1 ET
1 KE
1 RW
1 SD
1 SS
1 TZ
1 UG
2 BO
2 BR
2 CO
2 EC
2 GY
2 PE
2 VE
3 CN
4 CA
4 US
5 MN
5 RU
6 CN
7 CN
7 KZ
CodePudding user response:
You need to use GROUP BY
and COUNT
.
Maybe that SQL Query may help you :
select count(riverId)
from your_table
group by Country
CodePudding user response:
SELECT riverID, COUNT(*) AS num_countries
FROM table
GROUP BY riverID
HAVING num_countries = 1