leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 3a166d7622512b15902d0dc8289c5921f35f0a50
parent 92e14612641973b421d611c475d78620939567f7
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Thu, 13 Apr 2023 00:23:52 -0500

Second highest salary problem completion SQL

Diffstat:
Asecond-highest-salary/second-highest-salary.sql | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/second-highest-salary/second-highest-salary.sql b/second-highest-salary/second-highest-salary.sql @@ -0,0 +1,12 @@ +--Speed: 436ms Beats: 51.92% + +--This DISTINCT part is used in case two employees or more have the same salary but we want to find the next highest. +(SELECT DISTINCT E.salary as SecondHighestSalary +FROM Employee as E +ORDER BY E.salary DESC +--The first 1 is the offset and the second 1 is the number of rows to return. By doing this it offsets by 1 and selects one row meaning the second row. +LIMIT 1,1) +--This is used to return null if there are no records that are found as the second highest salary. +UNION +(SELECT NULL) +LIMIT 1;