All pastes #406172 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-03-22 05:05 UTC
rendered paste body
SELECT teamname FROM
  (
    SELECT teamname, COUNT(played) AS games_won  FROM 
      (
        SELECT teamname, played FROM  
          (
            SELECT teamnamehost AS teamname, teamnamevisitor AS played
            FROM game WHERE scorehost > scorevisitor
            UNION ALL SELECT teamnamevisitor AS team, teamnamehost AS played
            FROM game WHERE scorevisitor > scorehost
          ) b 
        ORDER BY teamname
      ) 
    GROUP BY teamname
  )
WHERE games_won = 
  (  
    SELECT MAX(games_won) AS games_won FROM 
    (
      SELECT teamname, COUNT(played) AS games_won  FROM 
        (
          SELECT teamname, played FROM  
            (
              SELECT teamnamehost AS teamname, teamnamevisitor AS played
              FROM game WHERE scorehost > scorevisitor
              UNION ALL SELECT teamnamevisitor AS team, teamnamehost AS played
              FROM game WHERE scorevisitor > scorehost
            ) b 
          ORDER BY teamname
        ) b
      GROUP BY teamname
    )  
  );