Yargi

Continents and Currencies

Oct 6th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.64 KB | None | 0 0
  1. SELECT d1.continent_code, d1.currency_code, d1.currency_usage FROM
  2.     (SELECT `c`.`continent_code`, `c`.`currency_code`,
  3.     COUNT(`c`.`currency_code`) AS `currency_usage` FROM countries as c
  4.     GROUP BY c.currency_code, c.continent_code HAVING currency_usage > 1) as d1
  5. LEFT JOIN
  6.     (SELECT `c`.`continent_code`,`c`.`currency_code`,
  7.     COUNT(`c`.`currency_code`) AS `currency_usage` FROM countries as c
  8.      GROUP BY c.currency_code, c.continent_code HAVING currency_usage > 1) as d2
  9. ON d1.continent_code = d2.continent_code AND d2.currency_usage > d1.currency_usage
  10.  
  11. WHERE d2.currency_usage IS NULL
  12. ORDER BY d1.continent_code, d1.currency_code;
Add Comment
Please, Sign In to add comment