(Continuously updated) 20201119-MySQL (Leetcode) Brushing Notes-HK

Summary of small pits encountered by MySQL-2

Small catalog:

  • Output NULL value, need to nest a layer of select outside

text:

  1. Output NULL value, need to nest a layer of select outside

If you use the following code to select, it will cause the result of the select result to be null to fail to return;
find the salary value with the second highest salary:

select distinct Salary as "SecondHighestSalary"
from Employee 
order by Salary desc 
limit 1,1

Perform NULL output processing, as follows:

select (
select distinct Salary f
rom Employee 
order by Salary desc 
limit 1,1) 
as "SecondHighestSalary"

Add a nested loop to extract the inner query results and assign them to SecondHighestSalary, so that when the return value is NULL, the NULL value can be output; otherwise, the output is:
{"headers": ["SecondHighestSalary"], "values": []}

Which
limit usage are:

select * from tableName limit i, n

tableName: table name
i: the index value of the query result (starting from 0 by default), when i=0, it can be omitted i
n: the number returned by the query result
i and n are separated by a comma ","

Guess you like

Origin blog.csdn.net/weixin_42012759/article/details/109806929