Skip to content

Commit a043ada

Browse files
fix: update sql solution to lc problem: No.1211 (#2690)
1 parent 5cce4a1 commit a043ada

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

solution/1200-1299/1211.Queries Quality and Percentage/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,31 @@ SELECT
9494
ROUND(AVG(rating / position), 2) AS quality,
9595
ROUND(AVG(rating < 3) * 100, 2) AS poor_query_percentage
9696
FROM Queries
97+
WHERE query_name IS NOT NULL
9798
GROUP BY 1;
9899
```
99100

101+
```sql
102+
# Write your MySQL query statement below
103+
SELECT
104+
IFNULL(query_name, 'null') AS query_name,
105+
ROUND(AVG(CAST(rating AS DECIMAL) / position), 2) AS quality,
106+
ROUND(
107+
(
108+
SUM(
109+
CASE
110+
WHEN rating < 3 THEN 1
111+
ELSE 0
112+
END
113+
) / NULLIF(COUNT(*), 0)
114+
) * 100,
115+
2
116+
) AS poor_query_percentage
117+
FROM Queries
118+
GROUP BY query_name WITH ROLLUP
119+
HAVING query_name IS NOT NULL;
120+
```
121+
100122
<!-- tabs:end -->
101123

102124
<!-- end -->

solution/1200-1299/1211.Queries Quality and Percentage/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,31 @@ SELECT
9191
ROUND(AVG(rating / position), 2) AS quality,
9292
ROUND(AVG(rating < 3) * 100, 2) AS poor_query_percentage
9393
FROM Queries
94+
WHERE query_name IS NOT NULL
9495
GROUP BY 1;
9596
```
9697

98+
```sql
99+
# Write your MySQL query statement below
100+
SELECT
101+
IFNULL(query_name, 'null') AS query_name,
102+
ROUND(AVG(CAST(rating AS DECIMAL) / position), 2) AS quality,
103+
ROUND(
104+
(
105+
SUM(
106+
CASE
107+
WHEN rating < 3 THEN 1
108+
ELSE 0
109+
END
110+
) / NULLIF(COUNT(*), 0)
111+
) * 100,
112+
2
113+
) AS poor_query_percentage
114+
FROM Queries
115+
GROUP BY query_name WITH ROLLUP
116+
HAVING query_name IS NOT NULL;
117+
```
118+
97119
<!-- tabs:end -->
98120

99121
<!-- end -->

solution/1200-1299/1211.Queries Quality and Percentage/Solution.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ SELECT
44
ROUND(AVG(rating / position), 2) AS quality,
55
ROUND(AVG(rating < 3) * 100, 2) AS poor_query_percentage
66
FROM Queries
7+
WHERE query_name IS NOT NULL
78
GROUP BY 1;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
IFNULL(query_name, 'null') AS query_name,
4+
ROUND(AVG(CAST(rating AS DECIMAL) / position), 2) AS quality,
5+
ROUND(
6+
(
7+
SUM(
8+
CASE
9+
WHEN rating < 3 THEN 1
10+
ELSE 0
11+
END
12+
) / NULLIF(COUNT(*), 0)
13+
) * 100,
14+
2
15+
) AS poor_query_percentage
16+
FROM Queries
17+
GROUP BY query_name WITH ROLLUP
18+
HAVING query_name IS NOT NULL;

0 commit comments

Comments
 (0)