解答

212

SQL文(クエリ)

SELECT
  year
  , hour
  , sum_rev
FROM
  (
    SELECT
      *
      , RANK() OVER (PARTITION BY year ORDER BY sum_rev DESC) 
    AS rank
    FROM
      (
        SELECT
          FORMAT_DATETIME("%Y", date_time) AS year
          , FORMAT_DATETIME("%H", date_time) AS hour
          , SUM(revenue) AS sum_rev
        FROM
          sample.sales
        GROUP BY
          year
          , hour
      )
  )
WHERE
  rank = 1

結果テーブル

結果テーブル

サポートページに戻る