← ALL CHALLENGES
CHALLENGE / INTERMEDIATE / READY TO QUERY

สมาชิก NATO อยู่ในภูมิภาคใดบ้าง?

ฝึก JOIN ข้อมูลสมาชิก NATO กับภูมิภาคตาม UN M49 แล้วสรุปจำนวนประเทศในแต่ละกลุ่ม

01 / THE QUESTION

Question

ประเทศสมาชิก NATO ปัจจุบันกระจายอยู่ในภูมิภาคและอนุภูมิภาคของ UN M49 อย่างไร?

02 / SOURCE TABLES

Tables to use

03 / RELATIONSHIP

ER diagram

ONE TO MANY RELATIONSHIP
country_geographycountry_iso_alpha3Key fieldun_m49_region_nameun_m49_subregion_name
country_organization_membershipcountry_iso_alpha3Join fieldorganization_codemembership_statusvalid_fromvalid_to

country_geography.country_iso_alpha3 = country_organization_membership.country_iso_alpha3 · one geography row to many membership intervals

04 / ANALYST GUIDE

Guide

Analysis requirements

  • เชื่อมตารางด้วย country_iso_alpha3
  • กรอง organization_code เป็น NATO และ membership_status เป็น member และใช้ valid_to IS NULL เพื่อเลือกสถานะปัจจุบัน ณ วันที่ตรวจสอบข้อมูล
  • นับรหัสประเทศแบบไม่ซ้ำ แยกตาม un_m49_region_name และ un_m49_subregion_name
  • แสดงกลุ่มและจำนวน แล้วตรวจรายชื่อประเทศเบื้องหลังผลรวมก่อนสรุป
  • UN M49 เป็นการจัดกลุ่มเพื่อใช้ทางสถิติ และข้อมูลการเป็นสมาชิกชุดนี้ไม่ใช่ประวัติที่ครบทุกช่วงเวลา

Suggested query

Expand suggested query
SQL / STARTER QUERY
SELECT g.un_m49_region_name, g.un_m49_subregion_name,
       COUNT(DISTINCT m.country_iso_alpha3) AS member_countries
FROM country_organization_membership AS m
JOIN country_geography AS g
  ON m.country_iso_alpha3 = g.country_iso_alpha3
WHERE m.organization_code = 'NATO'
  AND m.membership_status = 'member'
  AND m.valid_to IS NULL
GROUP BY g.un_m49_region_name, g.un_m49_subregion_name
ORDER BY member_countries DESC;