शुरू करेंमुफ़्त में शुरू करें

Gender और event के आधार पर reigning champions

पिछले अभ्यास में, आपने gender के आधार पर partition किया था ताकि एक gender का डेटा दूसरे gender के डेटा में न मिल जाए। लेकिन यदि आपके पास कई कॉलम हों, तो केवल एक कॉलम के आधार पर partition करने से बाकी कॉलमों के परिणाम आपस में मिल सकते हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

PostgreSQL Summary Stats और Window Functions

पाठ्यक्रम देखें

अभ्यास निर्देश

  • प्रत्येक वर्ष के events के पिछले champions को gender और event के अनुसार लौटाएँ.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

WITH Athletics_Gold AS (
  SELECT DISTINCT
    Gender, Year, Event, Country
  FROM Summer_Medals
  WHERE
    Year >= 2000 AND
    Discipline = 'Athletics' AND
    Event IN ('100M', '10000M') AND
    Medal = 'Gold')

SELECT
  Gender, Year, Event,
  Country AS Champion,
  -- Fetch the previous year's champion by gender and event
  ___ OVER (___
            ORDER BY Year ASC) AS Last_Champion
FROM Athletics_Gold
ORDER BY Event ASC, Gender ASC, Year ASC;
कोड संपादित करें और चलाएँ