196. Delete Duplicate Emails Total Accepted: 18532 Total Submissions: 97924 Difficulty: Easy Contributors: Admin Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. +—-+——————+ | Id | Email | +—-+——————+ | 1 | john@example.com | | 2 | bob@example.com | …
Category Archives: leetsql
Leetsql 182: Duplicate Emails
182. Duplicate Emails Total Accepted: 27110 Total Submissions: 73222 Difficulty: Easy Contributors: Admin Write a SQL query to find all duplicate emails in a table named Person. +—-+———+ | Id | Email | +—-+———+ | 1 | a@b.com | | 2 | c@d.com | | 3 | a@b.com | +—-+———+ For example, your query should …
Leetcode 181: Employees Earning More Than Their Managers
https://leetcode.com/problems/employees-earning-more-than-their-managers/ 181. Employees Earning More Than Their Managers Total Accepted: 27138 Total Submissions: 76486 Difficulty: Easy Contributors: Admin The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. +—-+——-+——–+———–+ | Id | Name | Salary | ManagerId | +—-+——-+——–+———–+ | 1 …
Continue reading “Leetcode 181: Employees Earning More Than Their Managers”
Leetcode 180: Consecutive Numbers
180. Consecutive Numbers Total Accepted: 12576 Total Submissions: 52571 Difficulty: Medium Contributors: Admin Write a SQL query to find all numbers that appear at least three times consecutively. +—-+—–+ | Id | Num | +—-+—–+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | …
Leetcode 178: Rank Score
https://leetcode.com/problems/rank-scores/ 178. Rank Scores Total Accepted: 13824 Total Submissions: 58154 Difficulty: Medium Contributors: Admin 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 …
Leetcode 262: Trips and Users
262. Trips and Users Total Accepted: 6774 Total Submissions: 43127 Difficulty: Hard Contributors: Admin The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’). +—-+———–+———–+———+——————–+———-+ | Id | …
Sql Cheat Sheet
http://www.w3schools.com/sql/sql_quickref.asp http://files.zeroturnaround.com/pdf/zt_sql_cheat_sheet.pdf
Leetsql 185: Department Top Three Salaries
185. Department Top Three Salaries Total Accepted: 8926 Total Submissions: 57724 Difficulty: Hard Contributors: Admin The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +—-+——-+——–+————–+ | Id | Name | Salary | DepartmentId | +—-+——-+——–+————–+ | 1 | Joe | 70000 | 1 …
Continue reading “Leetsql 185: Department Top Three Salaries”
LeetSql 177: Nth Highest Salary
177. Nth Highest Salary Total Accepted: 12870 Total Submissions: 80808 Difficulty: Medium Contributors: Admin Write a SQL query to get the nth highest salary from the Employee table. +—-+——–+ | Id | Salary | +—-+——–+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +—-+——–+ For example, given the …