Most Commonly Asked

Median

-- Find the median rating of users in gold member status across all platfforms

SELECT 
    PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY rating) AS median
FROM members
WHERE member_status = 'Gold'

Pivoting

-- Find whether NBA teams scored more at home or away in season 2022-2023
SELECT 
  team,
  MAX(CASE WHEN home_away = 'home' THEN points ELSE NULL END) AS home_points,
  MAX(CASE WHEN home_away = 'away' THEN points ELSE NULL END) AS away_points
FROM nba 
WHERE season = '2022-2023'
GROUP BY 1

Last updated