当前位置:网站首页>【每日SQL打卡】DAY 20丨查询结果的质量和占比【难度简单】
【每日SQL打卡】DAY 20丨查询结果的质量和占比【难度简单】
2022-07-29 11:43:00 【不吃西红柿】
难度简单
SQL架构
查询表 Queries:
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| query_name | varchar |
| result | varchar |
| position | int |
| rating | int |
+-------------+---------+
此表没有主键,并可能有重复的行。
此表包含了一些从数据库中收集的查询信息。
“位置”(position)列的值为 1 到 500 。
“评分”(rating)列的值为 1 到 5 。评分小于 3 的查询被定义为质量很差的查询。将查询结果的质量 quality 定义为:
各查询结果的评分与其位置之间比率的平均值。
将劣质查询百分比 poor_query_percentage 为:
评分小于 3 的查询结果占全部查询结果的百分比。
编写一组 SQL 来查找每次查询的名称(query_name)、质量(quality) 和 劣质查询百分比(poor_query_percentage)。
质量(quality) 和劣质查询百分比(poor_query_percentage) 都应四舍五入到小数点后两位。
查询结果格式如下所示:
Queries table:
+------------+-------------------+----------+--------+
| query_name | result | position | rating |
+------------+-------------------+----------+--------+
| Dog | Golden Retriever | 1 | 5 |
| Dog | German Shepherd | 2 | 5 |
| Dog | Mule | 200 | 1 |
| Cat | Shirazi | 5 | 2 |
| Cat | Siamese | 3 | 3 |
| Cat | Sphynx | 7 | 4 |
+------------+-------------------+----------+--------+
Result table:
+------------+---------+-----------------------+
| query_name | quality | poor_query_percentage |
+------------+---------+-----------------------+
| Dog | 2.50 | 33.33 |
| Cat | 0.66 | 33.33 |
+------------+---------+-----------------------+
Dog 查询结果的质量为 ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50
Dog 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33
Cat 查询结果的质量为 ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66
Cat 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33边栏推荐
- AI model risk assessment Part 2: core content
- Paddlelite compilation and code running through the disk
- 报表查询字段集sql摘记
- puzzle(017.5)联动归位
- 宝塔快速搭建自适应咖啡网站模板与管理系统源码实测
- 基础架构之分布式配置中心
- 深入理解C# 可空类型
- Learning with Recoverable Forgetting阅读心得
- "Knowledge Collection" article to understand mysql index!!(recommended collection)
- 如何开始为您的 Kubernetes 应用程序编写 Helm 图表
猜你喜欢

共建共享数字世界的根:阿里云打造全面的云原生开源生态
![[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code](/img/c1/f962f1c1d9f75732157d49a5d1d0d6.png)
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code

XSS漏洞分析

How to start writing helm charts for your kubernetes application

Kubernetes基本概念

IPv6 Foundation

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

为什么应该在开发环境中使用 Kubernetes

Qt 之自定义界面(实现无边框、可移动)

2022最新 wifi大师小程序独立版3.0.8
随机推荐
路径依赖 - 偶然决策导致的依赖。
Great golang Road
【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
socket+websocket
"100 Interview Knowledge Collections" 1. Interview Skills丨Do you really understand HR's careful thinking?
MySql启动、连接sqlog、主从复制、双机热备(开机时)
std::vector 拷贝、追加、嵌套访问
IPV6基础
微信怎么知道别人删除了你?批量检测方法(建群)
AI全流程开发难题破解之钥
如何对SQuAD1.1数据集进行预处理「详解版」
基础架构之分布式配置中心
“祁东黄花菜”是国家地理标志保护产品吗? 蚂蚁新村7月29日答案
如何在匹配行之前使用 grep 显示文件名和行号
【Untitled】
【Unity3D】场景切换、退出全屏、退出游戏
8. Interleave - understand ThreadPoolExecutor thread pool from architecture design to practice
Alluxio为Presto赋能跨云的自助服务能力
公司出了一款新产品,要不要招代理商?
为什么应该在开发环境中使用 Kubernetes