【leetcode SQL】Employees Earning More Than Their Managers

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  | Joe   | 70000  | 3         |
| 2  | Henry | 80000  | 4         |
| 3  | Sam   | 60000  | NULL      |
| 4  | Max   | 90000  | NULL      |
+----+-------+--------+-----------+

Given the Employee table, write a SQL query that finds out employees who earn more than
their managers. For the above table, Joe is the only employee who earns more than his manager.

+----------+
| Employee |
+----------+
| Joe      |
+----------+

解决方案如下:

# Write your MySQL query statement below
Select a.Name as Employee
from Employee a inner join Employee b on a.ManagerId=b.Id
where a.Salary>b.Salary

开始对sql感兴趣了~

时间: 2024-10-13 22:46:44

【leetcode SQL】Employees Earning More Than Their Managers的相关文章

【Leetcode】Employees Earning More Than Their Managers

题目链接:https://leetcode.com/problems/employees-earning-more-than-their-managers/ 题目: 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

【leetcode SQL】Customers Who Never Order

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. Table: Customers. +----+-------+ | Id | Name | +----+-------+ | 1 | Joe | | 2 | Henry | | 3 | Sam

【MS SQL】通过执行计划来分析SQL性能

如何知道一句SQL语句的执行效率呢,只知道下面3种: 1.通过SQL语句执行时磁盘的活动量(IO)信息来分析:SET STATISTICS IO ON (开启) / SET STATISTICS IO OFF (关闭) 2.通过SQL语句执行时语法分析.编译以及执行所消耗的时间:SET STATISTICS TIME ON (开启) / SET STATISTICS TIME OFF (关闭) 3.通过执行计划查看:Ctrl + L -------------------------------

【LeetCode 229】Majority Element II

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 思路: [LeetCode 169]Majority Element 的拓展,这回要求的是出现次数超过三分之一次的数字咯,动动我们的大脑思考下,这样的数最多会存在几个呢,当然是2个嘛.因此,接着上一题的方

【LeetCode OJ】Sum Root to Leaf Numbers

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 # Definition for a  binary tree node # class TreeNode: #     def __init__(self, x): #         self.val = x #         self.left = No

【LeetCode OJ】Longest Consecutive Sequence

Problem Link: http://oj.leetcode.com/problems/longest-consecutive-sequence/ This problem is a classical problem where we can reduce the running time by the help of hash table. By given a list of numbers, we can find the longest consecutive sequence b

【MS SQL】查看任务执行进度

备份或还原数据库时,我一般是用MS SQL工具向导来进行,由于工具向导没有显示任务执行过程的状态, 如果数据库比较大执行时间较长的话,对任务啥时候执行完成比较迷茫,如下面步骤以"备份"数据库为例: 1.选择要备份的数据库,右键选择"任务 -->备份": 2.设置好备份选项,点击"确定"按钮: 3.数据库备份中.... 4.其实,当备份选项设置好后,不点"确认"按钮,点击上方的"脚本"选项: 5.系统自

【LeetCode OJ】Word Ladder I

Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in this problem: Hash Table. One hash set is the words dictionary where we can check if a word is in the dictionary in O(1) time. The other hash set is us

【leetcode系列】String to Integer (atoi)

这个我就直接上代码了,最开始把"abc123"也算作合法的了,后来查了一下atoi的定义,把这种去掉了. public class Solution { public static int atoi(String inStr) { long result = 0L; /* * 网上查了一下,atoi函数的定义是如果第一个非空格字符存在,是数字或者正负号则开始做类型转换, * 之后检测到非数字(包括结束符\0)字符时停止转换,返回整型数.否则,返回零.可能的输入情况有: 1.空字符串 *