当前位置:网站首页>Leetcode MySQL database topic 177
Leetcode MySQL database topic 177
2022-06-29 09:58:00 【Water like ice】
177. Nth Highest Salary
1、 Questions and answers
Table:Employee
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
Write a SQL query to get the nth highest salary from the Employee table.
To write SQL from Employee Get the number in the table n The highest salary
answer :delimiter $$ create function getNthHighestSalary(N int) returns int begin declare n1 int; set n1=N-1; return ( select distinct Salary from Employee order by Salary desc limit n1,1 ); end $$
2、 Summary of knowledge points
- delimiter
- create function
- declare、set
1、 Why delimiter Because MySQL By default, a semicolon is used to end a command , When a command in the body of the function we define is written, it will end with a semicolon , and MySQL It will be mistaken that the function body has been defined , An error will be reported during operation . To do this, we need to define a new identifier to identify the end of a command .
2、
Create a new function :
Create function function_name(parameter_type)
returns return_type
begin
#Function_content
end
Related instructions :
Function name : Should be a legal identifier , And should not conflict with existing keywords . A function should belong to a database , have access to db_name.funciton_name Execute the database to which the current function belongs , Otherwise, it defaults to the current database .
parameter list : You can have one or more function parameters , Even without parameters . For each parameter , It consists of parameter name and parameter type .
Return value : Indicates the return value class type
The body of the function : The function body of a custom function consists of several available MySQL sentence , Process control , Variable declaration and other statements . It should be noted that the function body must contain return Return statement .
3、
mysql Stored procedure , There are two ways to define variables :
- Use set or select Direct assignment , The variable name is @ start .
for example :set @var=1;
You can declare... Anywhere in a conversation , The scope is the entire session , Called session variable . - With declare Keyword declared variables , Can only be used in stored procedures , Called a stored procedure variable ,
for example :
DECLARE var1 INT DEFAULT 0; Mainly used in the storage process , Or send parameters to storage .
Add
LeetCode Answers on :
select IFNULL((select distinct(Salary)
from Employee
order by Salary desc
limit 1,1),null) as SecondHighestSalary
边栏推荐
- linux环境下安装配置redis,并设置开机自启动
- A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
- c#判断数组是否包含另一个数组的任何项
- Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.
- CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
- Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit
- 数据源连接池未关闭的问题 Could not open JDBC Connection for transaction
- Official STM32 chip package download address stm32f10x stm32f40x Download
- ImageView picture fill problem
- A comparison of methods for fully automatic segmentation of tumors and involved nodes in PET/CT of h
猜你喜欢

Application of decorator mode, packaging ServletRequest and adding addparameter method

自定义mvc框架实现

How to traverse objects in the vector container

C语言中通过sprintf()函数构造sql语句

A 3D Dual Path U-Net of Cancer Segmentation Based on MRI

linux环境下安装配置redis,并设置开机自启动

Student增删gaih

Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks

A 2.5D Cancer Segmentation for MRI Images Based on U-Net

FreeRTOS(九)——队列
随机推荐
Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit
在Activity外使用startActivity()方法报错原因与解决办法
How to set Google Chrome as the default browser
2020-09-18 referer认证 url转义
股票炒股账号开户安全吗?是靠谱的吗?
Cloud management platform: 9 open source cloud management platforms (CMP)
sublime text3设置运行自己的Makefile
Summary of PHP memory horse technology research and killing methods
基于keil5自动配置stm32f103标准库的官网freertos移植
你必须知道的23个最有用的Elasticseaerch检索技巧
UE4 compile a single file (VS and editor start respectively)
367. 有效的完全平方数-二分法
C语言实现一种创建易管理易维护线程的方法
1424. 对角线遍历 II
kdevelop新建工程
Idea debugging fails, reporting jdwp no transports initialized, jvmtierror=agent_ ERROR_ TRANSPORT_ LOAD(196)
es报错NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
官方stm32芯片包下载地址 stm32f10x stm32f40x下载
Causes and solutions of error reporting by using startactivity() method outside the activity