-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2026-LowQualityProblems.sql
More file actions
65 lines (62 loc) · 2.66 KB
/
2026-LowQualityProblems.sql
File metadata and controls
65 lines (62 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- 2026. Low-Quality Problems
-- Table: Problems
-- +-------------+------+
-- | Column Name | Type |
-- +-------------+------+
-- | problem_id | int |
-- | likes | int |
-- | dislikes | int |
-- +-------------+------+
-- In SQL, problem_id is the primary key column for this table.
-- Each row of this table indicates the number of likes and dislikes for a LeetCode problem.
-- Find the IDs of the low-quality problems. A LeetCode problem is low-quality if the like percentage of the problem (number of likes divided by the total number of votes) is strictly less than 60%.
-- Return the result table ordered by problem_id in ascending order.
-- The result format is in the following example.
-- Example 1:
-- Input:
-- Problems table:
-- +------------+-------+----------+
-- | problem_id | likes | dislikes |
-- +------------+-------+----------+
-- | 6 | 1290 | 425 |
-- | 11 | 2677 | 8659 |
-- | 1 | 4446 | 2760 |
-- | 7 | 8569 | 6086 |
-- | 13 | 2050 | 4164 |
-- | 10 | 9002 | 7446 |
-- +------------+-------+----------+
-- Output:
-- +------------+
-- | problem_id |
-- +------------+
-- | 7 |
-- | 10 |
-- | 11 |
-- | 13 |
-- +------------+
-- Explanation: The like percentages are as follows:
-- - Problem 1: (4446 / (4446 + 2760)) * 100 = 61.69858%
-- - Problem 6: (1290 / (1290 + 425)) * 100 = 75.21866%
-- - Problem 7: (8569 / (8569 + 6086)) * 100 = 58.47151%
-- - Problem 10: (9002 / (9002 + 7446)) * 100 = 54.73006%
-- - Problem 11: (2677 / (2677 + 8659)) * 100 = 23.61503%
-- - Problem 13: (2050 / (2050 + 4164)) * 100 = 32.99002%
-- Problems 7, 10, 11, and 13 are low-quality problems because their like percentages are less than 60%.
-- Create table If Not Exists Problems (problem_id int, likes int, dislikes int)
-- Truncate table Problems
-- insert into Problems (problem_id, likes, dislikes) values ('6', '1290', '425')
-- insert into Problems (problem_id, likes, dislikes) values ('11', '2677', '8659')
-- insert into Problems (problem_id, likes, dislikes) values ('1', '4446', '2760')
-- insert into Problems (problem_id, likes, dislikes) values ('7', '8569', '6086')
-- insert into Problems (problem_id, likes, dislikes) values ('13', '2050', '4164')
-- insert into Problems (problem_id, likes, dislikes) values ('10', '9002', '7446')
-- Write your MySQL query statement below
SELECT
problem_id
FROM
Problems
WHERE
-- 如果一个力扣问题的喜欢率(喜欢数除以总投票数)
(likes / (likes + dislikes) * 100) < 60 -- 喜欢率严格低于 60% ,则该问题为低质量问题
ORDER BY
problem_id -- 按 problem_id 升序排列