Skip to content

Commit 1622aa0

Browse files
refactor 178, 181 and 183
1 parent 5f4f5ce commit 1622aa0

File tree

3 files changed

+0
-56
lines changed

3 files changed

+0
-56
lines changed

database/_178.sql

-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
-- Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.
2-
--
3-
-- +----+-------+
4-
-- | Id | Score |
5-
-- +----+-------+
6-
-- | 1 | 3.50 |
7-
-- | 2 | 3.65 |
8-
-- | 3 | 4.00 |
9-
-- | 4 | 3.85 |
10-
-- | 5 | 4.00 |
11-
-- | 6 | 3.65 |
12-
-- +----+-------+
13-
-- For example, given the above Scores table, your query should generate the following report (order by highest score):
14-
--
15-
-- +-------+------+
16-
-- | Score | Rank |
17-
-- +-------+------+
18-
-- | 4.00 | 1 |
19-
-- | 4.00 | 1 |
20-
-- | 3.85 | 2 |
21-
-- | 3.65 | 3 |
22-
-- | 3.65 | 3 |
23-
-- | 3.50 | 4 |
24-
-- +-------+------+
25-
26-
-- # Write your MySQL query statement below
271
select Score,
282
(select count(distinct Score) from Scores where Score >= s.Score) Rank
293
from Scores s

database/_181.sql

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
-- Write your MySQL query statement below
21
select e.Name as Employee from Employee e left join Employee b on e.ManagerId = b.Id where e.Salary > b.Salary;

database/_183.sql

-29
Original file line numberDiff line numberDiff line change
@@ -1,30 +1 @@
1-
-- Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.
2-
--
3-
-- Table: Customers.
4-
--
5-
-- +----+-------+
6-
-- | Id | Name |
7-
-- +----+-------+
8-
-- | 1 | Joe |
9-
-- | 2 | Henry |
10-
-- | 3 | Sam |
11-
-- | 4 | Max |
12-
-- +----+-------+
13-
-- Table: Orders.
14-
--
15-
-- +----+------------+
16-
-- | Id | CustomerId |
17-
-- +----+------------+
18-
-- | 1 | 3 |
19-
-- | 2 | 1 |
20-
-- +----+------------+
21-
-- Using the above tables as example, return the following:
22-
--
23-
-- +-----------+
24-
-- | Customers |
25-
-- +-----------+
26-
-- | Henry |
27-
-- | Max |
28-
-- +-----------+
29-
301
select Name as Customers from Customers left join Orders on Customers.Id = Orders.CustomerId where Orders.CustomerId is Null;

0 commit comments

Comments
 (0)