楼主: Myron2017
跳转到指定楼层
上一主题 下一主题
收起左侧

刷题记录帖子

🔗
 楼主| Myron2017 2026-11-23 11:59:42 | 只看该作者
全局:
2987. Find Expensive Cities
Easy
Topics
SQL Schema
Pandas Schema
Table: Listings

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| listing_id  | int     |
| city        | varchar |
| price       | int     |
+-------------+---------+
listing_id is column of unique values for this table.
This table contains listing_id, city, and price.
Write a solution to find cities where the average home prices exceed the national average home price.

Return the result table sorted by city in ascending order.

The result format is in the following example.



Example 1:

Input:
Listings table:
+------------+--------------+---------+
| listing_id | city         | price   |
+------------+--------------+---------+
| 113        | LosAngeles   | 7560386 |
| 136        | SanFrancisco | 2380268 |     
| 92         | Chicago      | 9833209 |
| 60         | Chicago      | 5147582 |
| 8          | Chicago      | 5274441 |  
| 79         | SanFrancisco | 8372065 |
| 37         | Chicago      | 7939595 |
| 53         | LosAngeles   | 4965123 |
| 178        | SanFrancisco | 999207  |
| 51         | NewYork      | 5951718 |
| 121        | NewYork      | 2893760 |
+------------+--------------+---------+
Output
+------------+
| city       |
+------------+
| Chicago    |
| LosAngeles |  
+------------+
Explanation
The national average home price is $6,122,059.45. Among the cities listed:
- Chicago has an average price of $7,048,706.75
- Los Angeles has an average price of $6,277,754.5
- San Francisco has an average price of $3,900,513.33
- New York has an average price of $4,422,739
Only Chicago and Los Angeles have average home prices exceeding the national average. Therefore, these two cities are included in the output table. The output table is sorted in ascending order based on the city names.
  1. # Write your MySQL query statement below
  2. SELECT city
  3. FROM Listings
  4. GROUP BY city
  5. HAVING AVG(price) > (SELECT AVG(price) FROM Listings)
  6. ORDER BY city;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:00:27 | 只看该作者
全局:
2988. Manager of the Largest Department
Medium
Topics
SQL Schema
Pandas Schema
Table: Employees

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| emp_id      | int     |
| emp_name    | varchar |
| dep_id      | int     |
| position    | varchar |
+-------------+---------+
emp_id is column of unique values for this table.
This table contains emp_id, emp_name, dep_id, and position.
Write a solution to find the name of the manager from the largest department. There may be multiple largest departments when the number of employees in those departments is the same.

Return the result table sorted by dep_id in ascending order.

The result format is in the following example.



Example 1:

Input:
Employees table:
+--------+----------+--------+---------------+
| emp_id | emp_name | dep_id | position      |
+--------+----------+--------+---------------+
| 156    | Michael  | 107    | Manager       |
| 112    | Lucas    | 107    | Consultant    |   
| 8      | Isabella | 101    | Manager       |
| 160    | Joseph   | 100    | Manager       |
| 80     | Aiden    | 100    | Engineer      |
| 190    | Skylar   | 100    | Freelancer    |
| 196    | Stella   | 101    | Coordinator   |
| 167    | Audrey   | 100    | Consultant    |
| 97     | Nathan   | 101    | Supervisor    |
| 128    | Ian      | 101    | Administrator |
| 81     | Ethan    | 107    | Administrator |
+--------+----------+--------+---------------+
Output
+--------------+--------+
| manager_name | dep_id |
+--------------+--------+
| Joseph       | 100    |
| Isabella     | 101    |
+--------------+--------+
Explanation
- Departments with IDs 100 and 101 each has a total of 4 employees, while department 107 has 3 employees. Since both departments 100 and 101 have an equal number of employees, their respective managers will be included.
Output table is ordered by dep_id in ascending order.
  1. # Write your MySQL query statement below
  2. WITH dep_cnt AS (
  3.     SELECT dep_id, COUNT(*) AS cnt
  4.     FROM Employees
  5.     GROUP BY dep_id
  6. )
  7. SELECT
  8.     e.emp_name AS manager_name,
  9.     e.dep_id
  10. FROM Employees e
  11. JOIN dep_cnt d ON e.dep_id = d.dep_id
  12. WHERE e.position = 'Manager'
  13.   AND d.cnt = (SELECT MAX(cnt) FROM dep_cnt)
  14. ORDER BY e.dep_id;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:01:03 | 只看该作者
全局:
2989. Class Performance
Medium
Topics
SQL Schema
Pandas Schema
Table: Scores

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| student_id   | int     |
| student_name | varchar |
| assignment1  | int     |
| assignment2  | int     |
| assignment3  | int     |
+--------------+---------+
student_id is column of unique values for this table.
This table contains student_id, student_name, assignment1, assignment2, and assignment3.
Write a solution to calculate the difference in the total score (sum of all 3 assignments) between the highest score obtained by students and the lowest score obtained by them.

Return the result table in any order.

The result format is in the following example.



Example 1:

Input:
Scores table:
+------------+--------------+-------------+-------------+-------------+
| student_id | student_name | assignment1 | assignment2 | assignment3 |
+------------+--------------+-------------+-------------+-------------+
| 309        | Owen         | 88          | 47          | 87          |
| 321        | Claire       | 98          | 95          | 37          |     
| 338        | Julian       | 100         | 64          | 43          |  
| 423        | Peyton       | 60          | 44          | 47          |  
| 896        | David        | 32          | 37          | 50          |
| 235        | Camila       | 31          | 53          | 69          |
+------------+--------------+-------------+-------------+-------------+
Output
+---------------------+
| difference_in_score |
+---------------------+
| 111                 |
+---------------------+
Explanation
- student_id 309 has a total score of 88 + 47 + 87 = 222.
- student_id 321 has a total score of 98 + 95 + 37 = 230.
- student_id 338 has a total score of 100 + 64 + 43 = 207.
- student_id 423 has a total score of 60 + 44 + 47 = 151.
- student_id 896 has a total score of 32 + 37 + 50 = 119.
- student_id 235 has a total score of 31 + 53 + 69 = 153.
student_id 321 has the highest score of 230, while student_id 896 has the lowest score of 119. Therefore, the difference between them is 111.
  1. # Write your MySQL query statement below
  2. SELECT
  3.     MAX(assignment1 + assignment2 + assignment3)
  4.   - MIN(assignment1 + assignment2 + assignment3) AS difference_in_score
  5. FROM Scores;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:01:38 | 只看该作者
全局:
2990. Loan Types
Easy
Topics
SQL Schema
Pandas Schema
Table: Loans

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| loan_id     | int     |
| user_id     | int     |
| loan_type   | varchar |
+-------------+---------+
loan_id is column of unique values for this table.
This table contains loan_id, user_id, and loan_type.
Write a solution to find all distinct user_id's that have at least one Refinance loan type and at least one Mortgage loan type.

Return the result table ordered by user_id in ascending order.

The result format is in the following example.



Example 1:

Input:
Loans table:
+---------+---------+-----------+
| loan_id | user_id | loan_type |
+---------+---------+-----------+
| 683     | 101     | Mortgage  |
| 218     | 101     | AutoLoan  |
| 802     | 101     | Inschool  |
| 593     | 102     | Mortgage  |
| 138     | 102     | Refinance |
| 294     | 102     | Inschool  |
| 308     | 103     | Refinance |
| 389     | 104     | Mortgage  |
+---------+---------+-----------+
Output
+---------+
| user_id |
+---------+
| 102     |
+---------+
Explanation
- User_id 101 has three loan types, one of which is a Mortgage. However, this user does not have any loan type categorized as Refinance, so user_id 101 won't be considered.
- User_id 102 possesses three loan types: one for Mortgage and one for Refinance. Hence, user_id 102 will be included in the result.
- User_id 103 has a loan type of Refinance but lacks a Mortgage loan type, so user_id 103 won't be considered.
- User_id 104 has a Mortgage loan type but doesn't have a Refinance loan type, thus, user_id 104 won't be considered.
Output table is ordered by user_id in ascending order.
  1. # Write your MySQL query statement below
  2. SELECT user_id
  3. FROM Loans
  4. GROUP BY user_id
  5. HAVING SUM(loan_type = 'Mortgage') > 0
  6.    AND SUM(loan_type = 'Refinance') > 0
  7. ORDER BY user_id;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:02:22 | 只看该作者
全局:
2991. Top Three Wineries
Hard
Topics
SQL Schema
Pandas Schema
Table: Wineries

+-------------+----------+
| Column Name | Type     |
+-------------+----------+
| id          | int      |
| country     | varchar  |
| points      | int      |
| winery      | varchar  |
+-------------+----------+
id is column of unique values for this table.
This table contains id, country, points, and winery.
Write a solution to find the top three wineries in each country based on their total points. If multiple wineries have the same total points, order them by winery name in ascending order. If there's no second winery, output 'No second winery,' and if there's no third winery, output 'No third winery.'

Return the result table ordered by country in ascending order.

The result format is in the following example.



Example 1:

Input:
Wineries table:
+-----+-----------+--------+-----------------+
| id  | country   | points | winery          |
+-----+-----------+--------+-----------------+
| 103 | Australia | 84     | WhisperingPines |
| 737 | Australia | 85     | GrapesGalore    |   
| 848 | Australia | 100    | HarmonyHill     |
| 222 | Hungary   | 60     | MoonlitCellars  |
| 116 | USA       | 47     | RoyalVines      |
| 124 | USA       | 45     | Eagle'sNest     |
| 648 | India     | 69     | SunsetVines     |
| 894 | USA       | 39     | RoyalVines      |  
| 677 | USA       | 9      | PacificCrest    |  
+-----+-----------+--------+-----------------+
Output:
+-----------+---------------------+-------------------+----------------------+
| country   | top_winery          | second_winery     | third_winery         |
+-----------+---------------------+-------------------+----------------------+
| Australia | HarmonyHill (100)   | GrapesGalore (85) | WhisperingPines (84) |
| Hungary   | MoonlitCellars (60) | No second winery  | No third winery      |
| India     | SunsetVines (69)    | No second winery  | No third winery      |  
| USA       | RoyalVines (86)     | Eagle'sNest (45)  | PacificCrest (9)     |
+-----------+---------------------+-------------------+----------------------+
Explanation
For Australia
- HarmonyHill Winery accumulates the highest score of 100 points in Australia.
- GrapesGalore Winery has a total of 85 points, securing the second-highest position in Australia.
- WhisperingPines Winery has a total of 80 points, ranking as the third-highest.
For Hungary
- MoonlitCellars is the sole winery, accruing 60 points, automatically making it the highest. There is no second or third winery.
For India
- SunsetVines is the sole winery, earning 69 points, making it the top winery. There is no second or third winery.
For the USA
- RoyalVines Wines accumulates a total of 47 + 39 = 86 points, claiming the highest position in the USA.
- Eagle'sNest has a total of 45 points, securing the second-highest position in the USA.
- PacificCrest accumulates 9 points, ranking as the third-highest winery in the USA
Output table is ordered by country in ascending order.
  1. # Write your MySQL query statement below
  2. WITH t AS (
  3.     SELECT country, winery, SUM(points) AS total
  4.     FROM Wineries
  5.     GROUP BY country, winery
  6. ),
  7. r AS (
  8.     SELECT
  9.         country,
  10.         winery,
  11.         total,
  12.         ROW_NUMBER() OVER (
  13.             PARTITION BY country
  14.             ORDER BY total DESC, winery ASC
  15.         ) AS rn
  16.     FROM t
  17. )
  18. SELECT
  19.     country,
  20.     MAX(CASE WHEN rn = 1 THEN CONCAT(winery, ' (', total, ')') END) AS top_winery,
  21.     COALESCE(
  22.         MAX(CASE WHEN rn = 2 THEN CONCAT(winery, ' (', total, ')') END),
  23.         'No second winery'
  24.     ) AS second_winery,
  25.     COALESCE(
  26.         MAX(CASE WHEN rn = 3 THEN CONCAT(winery, ' (', total, ')') END),
  27.         'No third winery'
  28.     ) AS third_winery
  29. FROM r
  30. GROUP BY country
  31. ORDER BY country;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:03:01 | 只看该作者
全局:
2993. Friday Purchases I
Medium
Topics
SQL Schema
Pandas Schema
Table: Purchases

+---------------+------+
| Column Name   | Type |
+---------------+------+
| user_id       | int  |
| purchase_date | date |
| amount_spend  | int  |
+---------------+------+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
Each row contains user id, purchase date, and amount spend.
Write a solution to calculate the total spending by users on each Friday of every week in November 2023. Output only weeks that include at least one purchase on a Friday.

Return the result table ordered by week of month in ascending order.

The result format is in the following example.



Example 1:

Input:
Purchases table:
+---------+---------------+--------------+
| user_id | purchase_date | amount_spend |
+---------+---------------+--------------+
| 11      | 2023-11-07    | 1126         |
| 15      | 2023-11-30    | 7473         |
| 17      | 2023-11-14    | 2414         |
| 12      | 2023-11-24    | 9692         |
| 8       | 2023-11-03    | 5117         |
| 1       | 2023-11-16    | 5241         |
| 10      | 2023-11-12    | 8266         |
| 13      | 2023-11-24    | 12000        |
+---------+---------------+--------------+
Output:
+---------------+---------------+--------------+
| week_of_month | purchase_date | total_amount |
+---------------+---------------+--------------+
| 1             | 2023-11-03    | 5117         |
| 4             | 2023-11-24    | 21692        |
+---------------+---------------+--------------+
Explanation:
- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03.
- For the second week of November 2023, there were no transactions on Friday, 2023-11-10.
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17.
- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692.
Output table is ordered by week_of_month in ascending order.
  1. # Write your MySQL query statement below
  2. SELECT
  3.     CEIL(DAY(purchase_date) / 7) AS week_of_month,
  4.     purchase_date,
  5.     SUM(amount_spend) AS total_amount
  6. FROM Purchases
  7. WHERE DAYOFWEEK(purchase_date) = 6
  8. GROUP BY purchase_date
  9. ORDER BY week_of_month;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:05:25 | 只看该作者
全局:
2994. Friday Purchases II
Hard
Topics
SQL Schema
Pandas Schema
Table: Purchases

+---------------+------+
| Column Name   | Type |
+---------------+------+
| user_id       | int  |
| purchase_date | date |
| amount_spend  | int  |
+---------------+------+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
Each row contains user id, purchase date, and amount spend.
Write a solution to calculate the total spending by users on each Friday of every week in November 2023. If there are no purchases on a particular Friday of a week, it will be considered as 0.

Return the result table ordered by week of month in ascending order.

The result format is in the following example.



Example 1:

Input:
Purchases table:
+---------+---------------+--------------+
| user_id | purchase_date | amount_spend |
+---------+---------------+--------------+
| 11      | 2023-11-07    | 1126         |
| 15      | 2023-11-30    | 7473         |
| 17      | 2023-11-14    | 2414         |
| 12      | 2023-11-24    | 9692         |
| 8       | 2023-11-03    | 5117         |
| 1       | 2023-11-16    | 5241         |
| 10      | 2023-11-12    | 8266         |
| 13      | 2023-11-24    | 12000        |
+---------+---------------+--------------+
Output:
+---------------+---------------+--------------+
| week_of_month | purchase_date | total_amount |
+---------------+---------------+--------------+
| 1             | 2023-11-03    | 5117         |
| 2             | 2023-11-10    | 0            |
| 3             | 2023-11-17    | 0            |
| 4             | 2023-11-24    | 21692        |
+---------------+---------------+--------------+
Explanation:
- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03.
- For the second week of November 2023, there were no transactions on Friday, 2023-11-10, resulting in a value of 0 in the output table for that day.
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17, reflected as 0 in the output table for that specific day.
- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692.
Output table is ordered by week_of_month in ascending order.
  1. # Write your MySQL query statement below
  2. WITH RECURSIVE fridays AS (
  3.     SELECT DATE '2023-11-03' AS purchase_date, 1 AS week_of_month
  4.     UNION ALL
  5.     SELECT DATE_ADD(purchase_date, INTERVAL 7 DAY), week_of_month + 1
  6.     FROM fridays
  7.     WHERE week_of_month < 4
  8. )
  9. SELECT
  10.     f.week_of_month,
  11.     f.purchase_date,
  12.     COALESCE(SUM(p.amount_spend), 0) AS total_amount
  13. FROM fridays f
  14. LEFT JOIN Purchases p
  15.        ON p.purchase_date = f.purchase_date
  16. GROUP BY f.week_of_month, f.purchase_date
  17. ORDER BY f.week_of_month;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:06:32 | 只看该作者
全局:
2995. Viewers Turned Streamers
Hard
Topics
SQL Schema
Pandas Schema
Table: Sessions

+---------------+----------+
| Column Name   | Type     |
+---------------+----------+
| user_id       | int      |
| session_start | datetime |
| session_end   | datetime |
| session_id    | int      |
| session_type  | enum     |
+---------------+----------+
session_id is column of unique values for this table.
session_type is an ENUM (category) type of (Viewer, Streamer).
This table contains user id, session start, session end, session id and session type.
Write a solution to find the number of streaming sessions for users whose first session was as a viewer.

Return the result table ordered by count of streaming sessions, user_id in descending order.

The result format is in the following example.



Example 1:

Input:
Sessions table:
+---------+---------------------+---------------------+------------+--------------+
| user_id | session_start       | session_end         | session_id | session_type |
+---------+---------------------+---------------------+------------+--------------+
| 101     | 2023-11-06 13:53:42 | 2023-11-06 14:05:42 | 375        | Viewer       |  
| 101     | 2023-11-22 16:45:21 | 2023-11-22 20:39:21 | 594        | Streamer     |   
| 102     | 2023-11-16 13:23:09 | 2023-11-16 16:10:09 | 777        | Streamer     |
| 102     | 2023-11-17 13:23:09 | 2023-11-17 16:10:09 | 778        | Streamer     |
| 101     | 2023-11-20 07:16:06 | 2023-11-20 08:33:06 | 315        | Streamer     |
| 104     | 2023-11-27 03:10:49 | 2023-11-27 03:30:49 | 797        | Viewer       |
| 103     | 2023-11-27 03:10:49 | 2023-11-27 03:30:49 | 798        | Streamer     |  
+---------+---------------------+---------------------+------------+--------------+
Output:
+---------+----------------+
| user_id | sessions_count |
+---------+----------------+
| 101     | 2              |
+---------+----------------+
Explanation
- user_id 101, initiated their initial session as a viewer on 2023-11-06 at 13:53:42, followed by two subsequent sessions as a Streamer, the count will be 2.
- user_id 102, although there are two sessions, the initial session was as a Streamer, so this user will be excluded.
- user_id 103 participated in only one session, which was as a Streamer, hence, it won't be considered.
- User_id 104 commenced their first session as a viewer but didn't have any subsequent sessions, therefore, they won't be included in the final count.
Output table is ordered by sessions count and user_id in descending order.
  1. # Write your MySQL query statement below
  2. WITH first_session AS (
  3.     SELECT
  4.         user_id,
  5.         session_type,
  6.         ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY session_start) AS rn
  7.     FROM Sessions
  8. )
  9. SELECT
  10.     user_id,
  11.     COUNT(*) AS sessions_count
  12. FROM Sessions
  13. WHERE session_type = 'Streamer'
  14.   AND user_id IN (
  15.       SELECT user_id
  16.       FROM first_session
  17.       WHERE rn = 1 AND session_type = 'Viewer'
  18.   )
  19. GROUP BY user_id
  20. ORDER BY sessions_count DESC, user_id DESC;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:07:18 | 只看该作者
全局:
3050. Pizza Toppings Cost Analysis
Medium
Topics
SQL Schema
Pandas Schema
Table: Toppings

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| topping_name | varchar |
| cost         | decimal |
+--------------+---------+
topping_name is the primary key for this table.
Each row of this table contains topping name and the cost of the topping.
Write a solution to calculate the total cost of all possible 3-topping pizza combinations from a given list of toppings. The total cost of toppings must be rounded to 2 decimal places.

Note:

Do not include the pizzas where a topping is repeated. For example, ‘Pepperoni, Pepperoni, Onion Pizza’.
Toppings must be listed in alphabetical order. For example, 'Chicken, Onions, Sausage'. 'Onion, Sausage, Chicken' is not acceptable.
Return the result table ordered by total cost in descending order and combination of toppings in ascending order.

The result format is in the following example.



Example 1:

Input:
Toppings table:
+--------------+------+
| topping_name | cost |
+--------------+------+
| Pepperoni    | 0.50 |
| Sausage      | 0.70 |
| Chicken      | 0.55 |
| Extra Cheese | 0.40 |
+--------------+------+
Output:
+--------------------------------+------------+
| pizza                          | total_cost |
+--------------------------------+------------+
| Chicken,Pepperoni,Sausage      | 1.75       |  
| Chicken,Extra Cheese,Sausage   | 1.65       |
| Extra Cheese,Pepperoni,Sausage | 1.60       |
| Chicken,Extra Cheese,Pepperoni | 1.45       |
+--------------------------------+------------+
Explanation:
There are only four different combinations possible with the three topings:
- Chicken, Pepperoni, Sausage: Total cost is $1.75 (Chicken $0.55, Pepperoni $0.50, Sausage $0.70).
- Chicken, Extra Cheese, Sausage: Total cost is $1.65 (Chicken $0.55, Extra Cheese $0.40, Sausage $0.70).
- Extra Cheese, Pepperoni, Sausage: Total cost is $1.60 (Extra Cheese $0.40, Pepperoni $0.50, Sausage $0.70).
- Chicken, Extra Cheese, Pepperoni: Total cost is $1.45 (Chicken $0.55, Extra Cheese $0.40, Pepperoni $0.50).
Output table is ordered by the total cost in descending order.
  1. # Write your MySQL query statement below
  2. SELECT
  3.     CONCAT_WS(',', t1.topping_name, t2.topping_name, t3.topping_name) AS pizza,
  4.     ROUND(t1.cost + t2.cost + t3.cost, 2) AS total_cost
  5. FROM Toppings t1
  6. JOIN Toppings t2 ON t1.topping_name < t2.topping_name
  7. JOIN Toppings t3 ON t2.topping_name < t3.topping_name
  8. ORDER BY total_cost DESC, pizza ASC;
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2026-11-23 12:08:04 | 只看该作者
全局:
3051. Find Candidates for Data Scientist Position
Easy
Topics
SQL Schema
Pandas Schema
Table: Candidates

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| candidate_id | int     |
| skill        | varchar |
+--------------+---------+
(candidate_id, skill) is the primary key (columns with unique values) for this table.
Each row includes candidate_id and skill.
Write a query to find the candidates best suited for a Data Scientist position. The candidate must be proficient in Python, Tableau, and PostgreSQL.

Return the result table ordered by candidate_id in ascending order.

The result format is in the following example.



Example 1:

Input:
Candidates table:
+---------------+--------------+
| candidate_id  | skill        |
+---------------+--------------+
| 123           | Python       |
| 234           | R            |
| 123           | Tableau      |
| 123           | PostgreSQL   |
| 234           | PowerBI      |
| 234           | SQL Server   |
| 147           | Python       |
| 147           | Tableau      |
| 147           | Java         |
| 147           | PostgreSQL   |
| 256           | Tableau      |
| 102           | DataAnalysis |
+---------------+--------------+
Output:
+--------------+
| candidate_id |  
+--------------+
| 123          |  
| 147          |
+--------------+
Explanation:
- Candidates 123 and 147 possess the necessary skills in Python, Tableau, and PostgreSQL for the data scientist position.
- Candidates 234 and 102 do not possess any of the required skills for this position.
- Candidate 256 has proficiency in Tableau but is missing skills in Python and PostgreSQL.
The output table is sorted by candidate_id in ascending order.
  1. # Write your MySQL query statement below
  2. SELECT candidate_id
  3. FROM Candidates
  4. WHERE skill IN ('Python', 'Tableau', 'PostgreSQL')
  5. GROUP BY candidate_id
  6. HAVING COUNT(DISTINCT skill) = 3
  7. ORDER BY candidate_id;
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表