当前位置:网站首页>【每日SQL打卡】DAY 26丨广告效果【难度简单】
【每日SQL打卡】DAY 26丨广告效果【难度简单】
2022-07-29 11:42:00 【不吃西红柿】
难度简单
SQL架构
表: Ads
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| ad_id | int |
| user_id | int |
| action | enum |
+---------------+---------+
(ad_id, user_id) 是该表的主键
该表的每一行包含一条广告的 ID(ad_id),用户的 ID(user_id) 和用户对广告采取的行为 (action)
action 列是一个枚举类型 ('Clicked', 'Viewed', 'Ignored') 。一家公司正在运营这些广告并想计算每条广告的效果。
广告效果用点击通过率(Click-Through Rate:CTR)来衡量,公式如下:
img
写一条SQL语句来查询每一条广告的 ctr ,
ctr 要保留两位小数。结果需要按 ctr降序、按 ad_id升序 进行排序。
查询结果示例如下:
Ads 表:
+-------+---------+---------+
| ad_id | user_id | action |
+-------+---------+---------+
| 1 | 1 | Clicked |
| 2 | 2 | Clicked |
| 3 | 3 | Viewed |
| 5 | 5 | Ignored |
| 1 | 7 | Ignored |
| 2 | 7 | Viewed |
| 3 | 5 | Clicked |
| 1 | 4 | Viewed |
| 2 | 11 | Viewed |
| 1 | 2 | Clicked |
+-------+---------+---------+
结果表:
+-------+-------+
| ad_id | ctr |
+-------+-------+
| 1 | 66.67 |
| 3 | 50.00 |
| 2 | 33.33 |
| 5 | 0.00 |
+-------+-------+
对于 ad_id = 1, ctr = (2/(2+1)) * 100 = 66.67
对于 ad_id = 2, ctr = (1/(1+2)) * 100 = 33.33
对于 ad_id = 3, ctr = (1/(1+1)) * 100 = 50.00
对于 ad_id = 5, ctr = 0.00, 注意 ad_id = 5 没有被点击 (Clicked) 或查看 (Viewed) 过
注意我们不关心 action 为 Ingnored 的广告
结果按 ctr(降序),ad_id(升序)排序边栏推荐
- Self collection online computer wallpaper PHP source code v2.0 adaptive end
- MarkDown高阶语法手册
- Meituan and hungry were interviewed by Hangzhou supervisors to implement the responsibility of food safety management and prohibit malicious competition
- Similarities and differences of QWidget, qdialog and qmainwindow
- c语言:来实现一个小程序n子棋(已五子棋为例)
- On CompareTo method in string
- 为什么应该在开发环境中使用 Kubernetes
- Starrocks technology insider: how to have both real-time update and fast query
- PL/SQL 事务
- INVALID_ARGUMENT : Invalid rank for input: modelInput Got: 3 Expected: 4 Please fix either the input
猜你喜欢

TCP和UDP

Based on the flask to write a small shopping mall project

Out-of-the-box problem-solving thinking, putting a "rearview mirror" on the unconscious life

MarkDown高阶语法手册

LeetCode_容斥原理_中等_223.矩形面积

8. Interleave - understand ThreadPoolExecutor thread pool from architecture design to practice

Exclusive interview | Cheng Li, chief technology officer of Alibaba: cloud + open source together form a credible foundation for the digital world
Xiaoxiao authorization system V5.0 happy version

Learning with Recoverable Forgetting阅读心得

Pyqt5 rapid development and practice 6.6 qformlayout & 6.7 nested layout & 6.8 qsplitter
随机推荐
LeetCode_容斥原理_中等_223.矩形面积
Package Delivery(贪心)
Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29
ASN.1接口描述语言详解
[SwiftUI 开发] @State @Binding @ObservedObject @EnvironmentObject
It is recommended to collect a thousand ways to write sql row to column!!
c语言:来实现一个小程序n子棋(已五子棋为例)
593. 有效的正方形 : 简单几何运用题
Is this it?TypeScript actually not difficult!(recommended collection)
Applied practical skills of deep reinforcement learning
深入理解C# 可空类型
Kubernetes基本概念
共建共享数字世界的根:阿里云打造全面的云原生开源生态
基于flask实现的mall商城---用户模块
【Untitled】
SkiaSharp of WPF custom painting to bounce ball (case)
Flink UDF 函数汇总
力扣sql刷题(四)
LMO·3rd - 报名通知
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界