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. PartyLocation的Post请求问题---debug

    这里,遇到了一个debug: @Override public void setPrimaryPartyLocation(PartyLocation partyLocation) { if (!get ...

  2. HDU 2819 Swap (二分匹配+破输出)

    题意:给定上一个01矩阵,让你变成一个对角全是 1 的矩阵. 析:二分匹配,把行和列看成两个集合,用匈牙利算法就可以解决,主要是在输出解,在比赛时一紧张不知道怎么输出了. 输出应该是要把 match[ ...

  3. c#操作json 使用JavaScriptSerializer

    需要引用:System.Web.Extensions /// <summary> /// json的信息.保证定义的变量和json的字段一样(也可以使用struct) /// </s ...

  4. Java打包多文件成zip

    package com.zh.java.util; import lombok.extern.slf4j.Slf4j; import java.io.File;import java.io.FileI ...

  5. Linux根目录结构

    1:  bin目录 此目录存放所有二进制命令(用户) 2:  boot目录 Linux内核及引导系统程序所需的目录 3:  dev目录 所有设备文件的目录(如声卡.磁盘.光驱) 4:  etc目录 二 ...

  6. P2488 [SDOI2011]工作安排 费用流

    \(\color{#0066ff}{ 题目描述 }\) 你的任务是制定出一个产品的分配方案,使得订单条件被满足,并且所有员工的愤怒值之和最小.由于我们并不想使用Special Judge,也为了使选手 ...

  7. P4449 于神之怒加强版

    \(\color{#0066ff}{ 题目描述 }\) 给定n,m,k,计算 \(\sum_{i=1}^n \sum_{j=1}^m \mathrm{gcd}(i,j)^k\) 对1000000007 ...

  8. Codeforces Round #534 (Div. 2) D. Game with modulo 交互题

    先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...

  9. CSS趣味

    谈一下小技巧: 1.先看一下问题,实现下图,只用于一个html元素有多少种实现方式? 假设我们的单标签是一个 div: <div></div> 定义如下通用CSS: div{ ...

  10. Django 05 自定义过滤器、自定义标签

    Django 05 自定义过滤器.自定义标签 一.自定义过滤器 #1.在项目目录下创建一个python package包 取名为common(这个名字可以自定义) #2.在common目录下创建一个t ...