当前位置:网站首页>This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
2022-07-04 02:43:00 【Mr.zhou_ Zxy】
Origin of problem :
topic :
surface : Employee
+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| salary | int |
+-------------+------+
Id Is the primary key column of the table .
Each row of the table contains information about the employee's salary .
Write a SQL Query to report Employee No n High wages . If there is no n A maximum wage , The query should be reported as null .
The query result format is as follows .
Example 1:
Input :
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
n = 2
Output :
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+
Example 2:
Input :
Employee surface :
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
+----+--------+
n = 2
Output :
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| null |
+------------------------+
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/nth-highest-salary
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Explain :
-- function
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set N = N - 1;
RETURN (
select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null)
as getNthHighestSalary
);
END
-- perform
select getNthHighestSalary(2)
Problems arise :

Problem analysis :
That's because it turns on bin-log journal , We must determine the following points in the function
deterministic Not sure of
no sql No, SQL sentence
reads sql data Read only data
modifies sql data Modifying data
contains sql contain SQL sentence
Because in function in , Only deterministic ,no sql,reads sql data Be supported . So open bin-log Must be after function Specify the parameters
Problem solving :
show variables like ‘log_bin_trust_function_creators’;

set global log_bin_trust_function_creators = 1

show variables like ‘log_bin_trust_function_creators’;

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set N = N - 1;
RETURN (
select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null)
as getNthHighestSalary
);
END

select getNthHighestSalary(2)

Add :
Using the above method will fail after the database is restarted , The following methods can be used for long-term effectiveness
[email protected]_zxy ~]# vim /etc/my.cnf
Add at the end
log_bin_trust_function_creators = 1
边栏推荐
- LV1 tire pressure monitoring
- Unspeakable Prometheus monitoring practice
- I stepped on a foundation pit today
- Global and Chinese market of contour projectors 2022-2028: Research Report on technology, participants, trends, market size and share
- Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
- Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
- How to subcontract uniapp and applet, detailed steps (illustration) # yyds dry goods inventory #
- Save Private Ryan - map building + voltage dp+deque+ shortest circuit
- Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
- 150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
猜你喜欢

C # learning notes: structure of CS documents

Bacteriostatic circle scanning correction template

Idea if a class cannot be found, it will be red

長文綜述:大腦中的熵、自由能、對稱性和動力學
![Backpropagation formula derivation [Li Hongyi deep learning version]](/img/ef/f76eae39c4f8716a0030a60c85b09c.gif)
Backpropagation formula derivation [Li Hongyi deep learning version]
![[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)](/img/36/e5b716f2f976eb474b673f85363dae.jpg)
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)

A fan summed up so many interview questions for you. There is always one you need!
![[software implementation series] software implementation interview questions with SQL joint query diagram](/img/8b/8718fea82f83a6169ea5d8c2e5b645.jpg)
[software implementation series] software implementation interview questions with SQL joint query diagram

Basic editing specifications and variables of shell script

VRRP+BFD
随机推荐
長文綜述:大腦中的熵、自由能、對稱性和動力學
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
Mysql to PostgreSQL real-time data synchronization practice sharing
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
Crawler practice website image batch download
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
求esp32C3板子連接mssql方法
Amélioration de l'efficacité de la requête 10 fois! 3 solutions d'optimisation pour résoudre le problème de pagination profonde MySQL
Life cycle of instance variables, static variables and local variables
Portapack application development tutorial (XVII) nRF24L01 launch C
Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
15. System limitations and options
Buuctf QR code
Example 072 calculation of salary it is known that the base salary of an employee of a company is 500 yuan. The amount of software sold by the employee and the Commission method are as follows: Sales
Advanced learning of MySQL -- Application -- index
Redis transaction
Kiss number + close contact problem
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon