Skip to content

Instantly share code, notes, and snippets.

@shunsugai
Created February 16, 2021 12:06
Show Gist options
  • Save shunsugai/6ee4e94d66e2213f891c0e9183710b72 to your computer and use it in GitHub Desktop.
Save shunsugai/6ee4e94d66e2213f891c0e9183710b72 to your computer and use it in GitHub Desktop.
イベント・潮位別成功率
WITH all_waves AS (
SELECT
CONCAT(
CAST(job_id AS VARCHAR),
'-',
CAST(details.quota_num AS VARCHAR)
) AS wave_id,
job_id,
details.quota_num,
details.event_type.name AS event,
details.water_level.name AS water_level
FROM
salmon_run_stats
CROSS JOIN UNNEST(wave_details) AS t(details)
),
failure_waves AS (
SELECT
CONCAT(
CAST(job_id AS VARCHAR),
'-',
CAST(
element_at(wave_details, job_result.failure_wave).quota_num AS VARCHAR
)
) AS wave_id,
false AS is_clear
FROM
salmon_run_stats
WHERE
job_result.is_clear = false
)
SELECT
all_waves.water_level,
all_waves.event,
COUNT(*) AS count,
COUNT(
is_clear = false
OR NULL
) AS failure_count,
100 - (CAST(
COUNT(
is_clear = false
OR NULL
) AS DOUBLE
) / COUNT(*) * 100) AS clear_rate
FROM
all_waves
LEFT JOIN failure_waves ON all_waves.wave_id = failure_waves.wave_id
GROUP BY
1,
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment