Accounts
"Low Salary"
: All the salaries strictly less than $20000
."Average Salary"
: All the salaries in the inclusive range [$20000, $50000]
."High Salary"
: All the salaries strictly greater than $50000
.제출한 쿼리 :
SELECT 'Low Salary' AS category
, COUNT(*) AS accounts_count
FROM Accounts
WHERE income < 20000
UNION ALL
SELECT 'Average Salary' AS category
, COUNT(*) AS accounts_count
FROM Accounts
WHERE income BETWEEN 20000 AND 50000
UNION ALL
SELECT 'High Salary' AS category
, COUNT(*) AS accounts_count
FROM Accounts
WHERE income > 50000;
Employees
$30000
and whose manager left the company. When a manager leaves the company, their information is deleted from the Employees
table, but the reports still have their manager_id
set to the manager that left.employee_id
.제출한 쿼리 :
SELECT employee_id
FROM Employees e1
WHERE salary < 30000
AND manager_id IS NOT NULL
AND manager_id NOT IN (SELECT employee_id FROM Employees)
ORDER BY employee_id;
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| student | varchar |
+-------------+---------+
id is the primary key (unique value) column for this table.
Each row of this table indicates the name and the ID of a student.
id is a continuous increment.
Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.
Return the result table ordered by id
in ascending order.
제출한 쿼리 :
SELECT CASE WHEN (s.id % 2 <> 0) AND s.id = (SELECT COUNT(*) FROM Seat) THEN s.id
WHEN s.id % 2 = 0 THEN s.id - 1
ELSE s.id + 1
END AS id, student
FROM Seat AS s
ORDER BY id
Movies
Users
MovieRating
February 2020
. In case of a tie, return the lexicographically smaller movie name.제출한 쿼리 :
SELECT name AS results
FROM MovieRating
JOIN Users USING(user_id)
GROUP BY name
ORDER BY COUNT(*) DESC, name
LIMIT 1
UNION ALL
SELECT title AS results
FROM MovieRating
JOIN Movies USING(movie_id)
WHERE EXTRACT(YEAR_MONTH FROM created_at) = 202002
GROUP BY title
ORDER BY AVG(rating) DESC, title
LIMIT 1);
Customer
average_amount
should be rounded to two decimal places.visited_on
in ascending order.제출한 쿼리 :
SELECT visited_on
, ( SELECT SUM(amount)
FROM customer
WHERE visited_on
BETWEEN DATE_SUB(c.visited_on, INTERVAL 6 DAY) AND c.visited_on
) AS amount
, ROUND( (SELECT SUM(amount) / 7
FROM customer
WHERE visited_on
BETWEEN DATE_SUB(c.visited_on, INTERVAL 6 DAY) AND c.visited_on
), 2
) AS average_amount
FROM customer c
WHERE visited_on >= (SELECT DATE_ADD(MIN(visited_on), INTERVAL 6 DAY)
FROM customer
)
GROUP BY visited_on;
오늘의 TMI
새로운 물고기 데려왔다...!