N_Damyanov

15. *Continents and Currencies

Jun 7th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.60 KB | None | 0 0
  1. CREATE TABLE groups_currency
  2. SELECT
  3.     continent_code,
  4.     currency_code,
  5.     count(currency_code) AS currency_usage
  6. FROM countries
  7. GROUP BY continent_code, currency_code
  8. HAVING currency_usage > 1;
  9.  
  10. SELECT
  11.     allgr.continent_code,
  12.     allgr.currency_code,
  13.     allgr.currency_usage
  14. FROM
  15.     groups_currency AS allgr,
  16.     (SELECT
  17.         continent_code,
  18.         currency_code,
  19.         max(currency_usage) AS currency_usage
  20.     FROM
  21.         groups_currency
  22.     GROUP BY continent_code
  23.     ) AS maxims
  24. WHERE allgr.continent_code = maxims.continent_code AND allgr.currency_usage = maxims.currency_usage
  25. ORDER BY
  26.     continent_code,
  27.     currency_code;
Add Comment
Please, Sign In to add comment