Advertisement
Guest User

Continents and Currencies

a guest
Feb 17th, 2018
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.63 KB | None | 0 0
  1. CREATE 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`
  5. GROUP BY `c`.`continent_code`,`c`.`currency_code`
  6. HAVING `currency_usage` > 1
  7. ORDER BY `c`.`continent_code` , `c`.`currency_code`;
  8.  
  9. SELECT
  10.     `cc`.*
  11. FROM
  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`
  16. WHERE
  17.     `cc2`.`currency_usage` IS NULL;
  18.    
  19. DROP TABLE `continents_currencies`;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement