Skip to content

Improved tasks 175-184 #1982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/g0101_0200/s0175_combine_two_tables/script.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Write your MySQL query statement below
# #Easy #Database #SQL_I_Day_5_Union #2022_06_26_Time_491_ms_(32.30%)_Space_0B_(100.00%)
SELECT FirstName, LastName, City, State
FROM Person LEFT JOIN Address USING (PersonId)
SELECT
FirstName,
LastName,
City,
State
FROM
Person
LEFT JOIN
Address
USING (PersonId);
16 changes: 10 additions & 6 deletions src/main/java/g0101_0200/s0176_second_highest_salary/script.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Write your MySQL query statement below
# #Medium #Database #SQL_I_Day_4_Union_and_Select
# #2022_07_10_Time_225_ms_(73.10%)_Space_0B_(100.00%)
SELECT ifnull(
(SELECT distinct(Salary)
FROM Employee
ORDER BY Salary DESC
LIMIT 1
OFFSET 1), NULL) SecondHighestSalary;
SELECT
IFNULL(
(
SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET 1
),
NULL
) AS SecondHighestSalary;
9 changes: 8 additions & 1 deletion src/main/java/g0101_0200/s0178_rank_scores/script.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Write your MySQL query statement below
# #Medium #Database #2022_06_26_Time_290_ms_(66.73%)_Space_0B_(100.00%)
select Score, DENSE_RANK() OVER(order by Score Desc) as "Rank" from Scores order by "Rank" Asc;
SELECT
Score,
DENSE_RANK() OVER (ORDER BY Score DESC) AS Rank
FROM
Scores
ORDER BY
Rank ASC;

14 changes: 9 additions & 5 deletions src/main/java/g0101_0200/s0180_consecutive_numbers/script.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Write your MySQL query statement below
# #Medium #Database #2024_07_15_Time_469_ms_(89.19%)_Space_0B_(100.00%)
SELECT DISTINCT l1.num AS ConsecutiveNums
FROM Logs l1
JOIN Logs l2 ON l1.id = l2.id - 1
JOIN Logs l3 ON l1.id = l3.id - 2
WHERE l1.num = l2.num AND l2.num = l3.num;
SELECT DISTINCT
l1.num AS ConsecutiveNums
FROM
Logs l1
JOIN Logs l2 ON l1.id = l2.id - 1
JOIN Logs l3 ON l1.id = l3.id - 2
WHERE
l1.num = l2.num
AND l2.num = l3.num;
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Write your MySQL query statement below
# #Easy #Database #2022_06_27_Time_315_ms_(94.44%)_Space_0B_(100.00%)
select a.Name as Employee from Employee a left join Employee b on a.ManagerId=b.Id
where a.Salary > b.Salary and a.ManagerId is not null
SELECT
a.Name AS Employee
FROM
Employee a
LEFT JOIN Employee b ON a.ManagerId = b.Id
WHERE
a.Salary > b.Salary
AND a.ManagerId IS NOT NULL;
10 changes: 9 additions & 1 deletion src/main/java/g0101_0200/s0182_duplicate_emails/script.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Write your MySQL query statement below
# #Easy #Database #SQL_I_Day_10_Where #2022_06_27_Time_303_ms_(92.08%)_Space_0B_(100.00%)
SELECT Email FROM Person GROUP BY Email HAVING COUNT(Email) > 1;
SELECT
Email
FROM
Person
GROUP BY
Email
HAVING
COUNT(Email) > 1;

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Write your MySQL query statement below
# #Easy #Database #SQL_I_Day_1_Select #2022_06_27_Time_376_ms_(98.73%)_Space_0B_(100.00%)
SELECT c.Name as Customers
FROM Customers as c
LEFT JOIN Orders as o
ON c.Id = o.CustomerId
WHERE o.CustomerId is null
SELECT
c.Name AS Customers
FROM
Customers AS c
LEFT JOIN Orders AS o ON c.Id = o.CustomerId
WHERE
o.CustomerId IS NULL;
25 changes: 15 additions & 10 deletions src/main/java/g0101_0200/s0184_department_highest_salary/script.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ SELECT
Sel.Name AS Employee,
Sel.Salary AS Salary
FROM
(
SELECT
Name,
Salary,
DepartmentId,
DENSE_RANK() OVER (PARTITION BY DepartmentId ORDER BY Salary DESC) AS dr
FROM Employee
) AS Sel
INNER JOIN Department d ON d.Id = Sel.DepartmentId
WHERE Sel.dr = 1
(
SELECT
Name,
Salary,
DepartmentId,
DENSE_RANK() OVER (
PARTITION BY DepartmentId
ORDER BY Salary DESC
) AS dr
FROM
Employee
) AS Sel
INNER JOIN Department d ON d.Id = Sel.DepartmentId
WHERE
Sel.dr = 1;