188 평균 이외의 지표로 세그먼트의 진정한 평가를 수행하기
국가별 사용자 참여도를 평균값, 중앙값, 표준편차로 구하는 SQL 문입니다.
WITH
master
AS
(
SELECT
user_pseudo_id
,
MAX
(geo.country)
AS
country
,
SUM
((
SELECT
value.int_value
FROM
UNNEST(event_params)
WHERE
key
=
'engagement_time_msec'
)) / 1000
AS
engagement_time
FROM
`bigquery-
public
-data.ga4_obfuscated_sample_ecommerce.events_20210131`
GROUP
BY
user_pseudo_id)
, a
AS
(
SELECT
country,
COUNT
(
DISTINCT
user_pseudo_id)
AS
users
, ROUND(
AVG
(engagement_time), 1)
AS
average_engagement_time
FROM
master
GROUP
BY
country)
, m
AS
(
SELECT
DISTINCT
country
, ROUND(PERCENTILE_CONT(engagement_time, 0.5) OVER(PARTITION
BY
country), 1)
AS
median_engagement_time
, ROUND(STDDEV_POP(engagement_time) OVER(PARTITION
BY
country), 1)
AS
std_dev_engagement_time
FROM
master)
SELECT
a.country, a.users, a.average_engagement_time, m.median_engagement_time, m.std_dev_engagement_time
FROM
a
INNER
JOIN
m
ON
a.country = m.country
ORDER
BY
2
DESC
답글 남기기