力扣MYSQL练习
176编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。
select IFNULL((SELECT distinct salary
from employee
order by salary desc
limit 1,1),NULL)AS SECONDHIGHESTSALARY;
select max(salary) as SecondHighestSalary
from employee
where salary not in (select max(salary) from employee);
178编写一个 SQL 查询来实现分数排名。如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔”。
别人的解法,先去重,再count,这样效率好很多,,我那解法巨慢。
select Score,
(select count(*) from(select distinct Score s from Scores) temp where s>=Score) as Rank
from Scores
order by Score desc
力扣MYSQL练习的更多相关文章
- 力扣算法题—069x的平方根
实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 示例 ...
- JS数据结构第六篇 --- 二叉树力扣练习题
1.第226题:翻转二叉树 递归+迭代两种实现方式: /** 反转二叉树 * Definition for a binary tree node. * function TreeNode(val) { ...
- 力扣(LeetCode)删除排序链表中的重复元素II 个人题解
给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 思路和上一题类似(参考 力扣(LeetCode)删除排序链表中的重复元素 个人题解)) 只不过这里需要用到一个前 ...
- C++双指针滑动和利用Vector实现无重复字符的最长子串—力扣算法
题目: 力扣原题链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 给定一个字符串, ...
- LeetCode 1244. 力扣排行榜
地址 https://www.acwing.com/solution/LeetCode/content/5765/ 题目描述新一轮的「力扣杯」编程大赛即将启动,为了动态显示参赛者的得分数据,需要设计一 ...
- 力扣50题 Pow(x,n)
本题是力扣网第50题. 实现 pow(x, n) ,即计算 x 的 n 次幂函数. 采用递归和非递归思路python实现. class Solution: #递归思路 def myPow_recurs ...
- LeetCode(力扣)——Search in Rotated Sorted Array2 搜索旋转排序数组 python实现
题目描述: python实现 Search in Rotated Sorted Array2 搜索旋转排序数组 中文: 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0 ...
- LeetCode(力扣)——Search in Rotated Sorted Array 搜索旋转排序数组 python实现
题目描述: python实现 Search in Rotated Sorted Array 搜索旋转排序数组 中文:假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1 ...
- 力扣—Reorder List(重排链表)python实现
题目描述: 中文: 给定一个单链表 L:L0→L1→…→Ln-1→Ln ,将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→… 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点 ...
随机推荐
- C语言 sizeof()用法介绍
本文 转自https://www.cnblogs.com/huolong-blog/p/7587711.html 1. 定义 sizeof是一个操作符(operator). 其作用是返回 ...
- php 时间 日期
获取月初与月末 /** * 获取当前月初与月末时间 * * */ $month =8; $year = 2019; $startDay = $year . '-' . $month . '-1'; $ ...
- stylelint
"number-leading-zero": "never", // 去掉小数点前面的0 "prettier.stylelintIntegration ...
- 获取url参数(jq 扩展包)
(function($){ $.extend({ urlGet:function(url) { var getUrl = url ? url.split("?") : window ...
- Mybatis的解析和运行原理
Mybatis的解析和运行原理 Mybatis的运行过程大致分为两大步:第一步,读取配置文件缓存到Configuration对象,用以创建 SqlSessionFactory:第二步,SqlSessi ...
- Python之路Day09
函数 将某个功能封装到一个空间中就是一个函数 减少重复代码 函数体中存放的时代码 定义函数 def len(): def 关键字 len 函数名 -- 变量名 ()格式规定 :语句结束 调用函数 函数 ...
- date-fns时间库的基本使用
在react中使用date-fns: import sub_days from 'date-fns/sub_days'; import start_of_week from 'date-fns/sta ...
- 数据从mmsql导入mysql
SQL SERVER数据导入MYSQL 工具: navicat for mysql 百度搜一个安装就可以,前提是你已经安装了mysql 1,创建目标数据库 点击创建好的目标数据库website点的表一 ...
- Django | Unable to get repr for <class 'django.db.models.query.QuerySet'>
问题:在mysql中查询数据时,代码如下: skus = category.sku_set.filter(is_launched=True).order_by(sort_field) skus 取不到 ...
- Centos7 入门几个操作
http://www.wallcopper.com/linux/1650.html 创建文件软连接 ln -s 源路径 目标路径 查看软连接ls -il 服务操作:systemctl start fo ...