diff --git a/solution/1300-1399/1322.Ads Performance/README.md b/solution/1300-1399/1322.Ads Performance/README.md index e6726b41ecbb1..d4fdab083930d 100644 --- a/solution/1300-1399/1322.Ads Performance/README.md +++ b/solution/1300-1399/1322.Ads Performance/README.md @@ -77,7 +77,17 @@ action 列是一个枚举类型 ('Clicked', 'Viewed', 'Ignor ### **SQL** ```sql - +SELECT + ad_id, + Ifnull(ROUND(AVG(CASE + WHEN action = 'Clicked' THEN 1 + WHEN action = 'Viewed' THEN 0 + ELSE NULL + END) * 100, 2), 0) AS ctr +FROM ads +GROUP BY ad_id +ORDER BY ctr DESC, +ad_id ASC; ``` diff --git a/solution/1300-1399/1322.Ads Performance/README_EN.md b/solution/1300-1399/1322.Ads Performance/README_EN.md index d95cba495088b..5980d08a28ee9 100644 --- a/solution/1300-1399/1322.Ads Performance/README_EN.md +++ b/solution/1300-1399/1322.Ads Performance/README_EN.md @@ -75,7 +75,17 @@ Note that we do not care about Ignored Ads. ### **SQL** ```sql - +SELECT + ad_id, + Ifnull(ROUND(AVG(CASE + WHEN action = 'Clicked' THEN 1 + WHEN action = 'Viewed' THEN 0 + ELSE NULL + END) * 100, 2), 0) AS ctr +FROM ads +GROUP BY ad_id +ORDER BY ctr DESC, +ad_id ASC; ``` diff --git a/solution/1300-1399/1322.Ads Performance/Solution.sql b/solution/1300-1399/1322.Ads Performance/Solution.sql new file mode 100644 index 0000000000000..0452101b9ef4f --- /dev/null +++ b/solution/1300-1399/1322.Ads Performance/Solution.sql @@ -0,0 +1,12 @@ +# Write your MySQL query statement below +SELECT + ad_id, + Ifnull(ROUND(AVG(CASE + WHEN action = 'Clicked' THEN 1 + WHEN action = 'Viewed' THEN 0 + ELSE NULL + END) * 100, 2), 0) AS ctr +FROM ads +GROUP BY ad_id +ORDER BY ctr DESC, +ad_id ASC;