· 8 years ago · Feb 17, 2018, 09:52 AM
1CREATE TABLE IF NOT EXISTS `continents_currencies` AS SELECT `c`.`continent_code`,
2 `c`.`currency_code`,
3 COUNT(`c`.`currency_code`) AS `currency_usage` FROM
4 `countries` AS `c`
5GROUP BY `c`.`continent_code`,`c`.`currency_code`
6HAVING `currency_usage` > 1
7ORDER BY `c`.`continent_code` , `c`.`currency_code`;
8
9SELECT
10 `cc`.*
11FROM
12 `continents_currencies` AS `cc`
13 LEFT JOIN
14 `continents_currencies` AS `cc2` ON `cc`.`continent_code` = `cc2`.`continent_code`
15 AND `cc`.`currency_usage` < `cc2`.`currency_usage`
16WHERE
17 `cc2`.`currency_usage` IS NULL;
18
19DROP TABLE `continents_currencies`;