https://leetcode.com/problems/employees-earning-more-than-their-managers/description/

老师上课没分析这些的复杂度,我大概认为子查询要O(n^2)

一开始,直接用了子查询,2400ms....

# Write your MySQL query statement below
select T.name as Employee
from Employee as T
where T.Salary > (select Employee.salary from Employee where Employee.Id = T.ManagerId);

然后

标程有一个2000ms的,但我也认为他复杂度需要O(n^2)

SELECT
a.Name AS 'Employee'
FROM
Employee AS a,
Employee AS b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary
;

最后一个用了join,确实理论上会比较快一丢丢,但是总体来说我感觉还是O(n^2)啊,1800ms快了很多很多

SELECT
a.Name AS 'Employee'
From
Employee as a join Employee as b
on a.ManagerId = b.Id
where
a.Salary > b.Salary
;

leetcode 181 Employees Earning More Than Their Managers 不会分析的数据库复杂度的更多相关文章

  1. Leetcode 181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  2. LeetCode 181. Employees Earning More Than Their Managers (超过经理收入的员工)

    题目标签: 题目给了我们一个 员工表,包括经理.员工会有经理的id. 这里可以重复 利用两次 表格,表格a, 表格b,当a 员工的经理id  等于 b员工时候,在从中找到员工工资大于经理的.具体看co ...

  3. [LeetCode] 181. Employees Earning More Than Their Managers_Easy tag: SQL

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  4. 【SQL】181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  5. 181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  6. LeetCode SQL:Employees Earning More Than Their Managers

    # Write your MySQL query statement below SELECT a.Name FROM Employee AS a INNER JOIN Employee AS b O ...

  7. [LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  8. LeetCode - Employees Earning More Than Their Managers

    Description: The Employee table holds all employees including their managers. Every employee has an ...

  9. LeetCode——Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

随机推荐

  1. mysql--笔记1

    今日内容介绍1.MySQL数据库2.SQL语句=========================================================1 数据库概念 1.1: 什么是数据库 ...

  2. Bootstrap 的 Tooltip 和 Popover

    简介 Tooltip 指提示框,Popover 指弹出框. Tooltip 默认 Tooltip 功能是关闭的,使用前要手动开启. $(function () { $('[data-toggle=&q ...

  3. Picasso VS Glide

    原文: Introduction to Glide, Image Loader Library for Android, recommended by Google 在泰国举行的谷歌开发者论坛上,谷歌 ...

  4. 网站下载器WebZip、Httrack及AWWWB.COM网站克隆器

     动机 闲扯节点,可略读. 下载并试用这些软件并非是为了一己之私,模仿他人网站以图利.鉴于国内网络环境之艰苦,我等屌丝级半罐水程序员,纵有百度如诸葛大神万般协力相助,也似后主般无能不能解决工作和娱乐中 ...

  5. PreparedStatement预编译对象实现

    模糊查询   插入 同时插入两行数据   执行更新语句 删除操作          

  6. linux虚拟机与windows主机传输文件方法

    通过ssh    这种方法需要虚拟机内的linux安装ssh服务,默认是安装的。 首先检查ssh服务是开启的,通过shell下执行命令:service ssh status, 查看ssh服务是否已开启 ...

  7. Docker基本使用(二) Hello World

    Docker 允许你在容器内运行应用程序, 使用 docker run 命令来在容器内运行一个应用程序. 输出Hello world runoob@runoob:~$ docker run ubunt ...

  8. Glib学习笔记(三)

    你将学到什么 如何实现Object的方法 Object的方法 Object的public方法 在头文件声明一个函数,然后在源文件中实现函数即可 /* declaration in the header ...

  9. iOS Programming GitHub

    我把学习<iOS编程(第4版)>的相关代码放在了GitHub上: https://github.com/palanceli/iOSProgramming 学了一段时间之后,当要用到某个知识 ...

  10. 提交表单存在html标签报错-检测到有潜在危险的 Request.Form 值

    1..aspx页面 在.aspx文件头中加入这句<%@ Page validateRequest="false" %> 2.通用方法 修改web.config文件, & ...