Advertisement
horozov86

16. Monasteries by Country

Oct 8th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. CREATE TABLE monasteries(
  2.     id SERIAL PRIMARY KEY,
  3.     monastery_name VARCHAR(255),
  4.     country_code CHAR(2)
  5. );
  6.  
  7. INSERT INTO monasteries(monastery_name, country_code)
  8. VALUES
  9.     ('Rila Monastery "St. Ivan of Rila"', 'BG'),
  10.     ('Bachkovo Monastery "Virgin Mary"', 'BG'),
  11.     ('Troyan Monastery "Holy Mother''s Assumption"', 'BG'),
  12.     ('Kopan Monastery', 'NP'),
  13.     ('Thrangu Tashi Yangtse Monastery', 'NP'),
  14.     ('Shechen Tennyi Dargyeling Monastery', 'NP'),
  15.     ('Benchen Monastery', 'NP'),
  16.     ('Southern Shaolin Monastery', 'CN'),
  17.     ('Dabei Monastery', 'CN'),
  18.     ('Wa Sau Toi', 'CN'),
  19.     ('Lhunshigyia Monastery', 'CN'),
  20.     ('Rakya Monastery', 'CN'),
  21.     ('Monasteries of Meteora', 'GR'),
  22.     ('The Holy Monastery of Stavronikita', 'GR'),
  23.     ('Taung Kalat Monastery', 'MM'),
  24.     ('Pa-Auk Forest Monastery', 'MM'),
  25.     ('Taktsang Palphug Monastery', 'BT'),
  26.     ('Sümela Monastery', 'TR');
  27.    
  28. ALTER TABLE countries
  29. ADD COLUMN
  30.     three_rivers BOOLEAN DEFAULT FALSE;
  31.    
  32. UPDATE
  33.     countries
  34.    
  35. SET three_rivers = (
  36.     SELECT
  37.         COUNT(*) >= 3
  38.     FROM
  39.         countries_rivers AS cr
  40.     WHERE
  41.         cr.country_code = countries.country_code
  42. );
  43.  
  44. SELECT
  45.     m.monastery_name AS monastery,
  46.     c.country_name AS country
  47. FROM
  48.     monasteries AS m
  49. JOIN
  50.     countries AS c
  51. USING
  52.     (country_code)
  53. WHERE
  54.     NOT three_rivers
  55. ORDER BY
  56.     monastery_name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement