1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/查询结果的质量和占比 [queries-quality-and-percentage].html

71 lines
2.6 KiB
HTML
Raw Normal View History

2023-12-09 18:53:53 +08:00
<p><code>Queries</code>&nbsp;表:&nbsp;</p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| query_name | varchar |
| result | varchar |
| position | int |
| rating | int |
+-------------+---------+
此表可能有重复的行。
此表包含了一些从数据库中收集的查询信息。
“位置”(<code>position</code>)列的值为 <strong>1</strong><strong>500</strong>
“评分”(<code>rating</code>)列的值为 <strong>1</strong><strong>5</strong> 。评分小于 3 的查询被定义为质量很差的查询。
</pre>
<p>&nbsp;</p>
<p>将查询结果的质量 <code>quality</code> 定义为:</p>
<blockquote>
<p>各查询结果的评分与其位置之间比率的平均值。</p>
</blockquote>
<p>将劣质查询百分比&nbsp;<code>poor_query_percentage</code> 为:</p>
<blockquote>
<p>评分小于 3 的查询结果占全部查询结果的百分比。</p>
</blockquote>
<p>编写解决方案,找出每次的&nbsp;<code>query_name</code>&nbsp;&nbsp;<code>quality</code>&nbsp;&nbsp;<code>poor_query_percentage</code></p>
<p><code>quality</code>&nbsp;&nbsp;<code>poor_query_percentage</code>&nbsp;都应 <strong>四舍五入到小数点后两位</strong></p>
<p><strong>任意顺序</strong> 返回结果表。</p>
<p>结果格式如下所示:</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+------------+-------------------+----------+--------+
<strong>输出:</strong>
+------------+---------+-----------------------+
| query_name | quality | poor_query_percentage |
+------------+---------+-----------------------+
| Dog | 2.50 | 33.33 |
| Cat | 0.66 | 33.33 |
+------------+---------+-----------------------+
<strong>解释:</strong>
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
</pre>