MySQL
SQL 基础
DDL 语句
show databases;
show tables;
desc table_name; # 获取表信息
show create table 表名; // 查询指定表的建表语句
数据类型
char(10) 不满10个会用空格填充,性能好一点
varchar(10) 变长字符串,性能差一点
CREATE TABLE table_employee(id int,eno char(10) comment '工号',ename varchar(10) comment '姓名',sex char(1) comment '性别',age tinyint unsigned comment '年龄',identification_card char(18) comment '身份证号',join_time date comment '入职时间'
) comment '员工表';
Leetcode
返回第N高的薪水
要点limit a,b 是从a+1行开始,返回b行数据。
sql执行顺序,从from开始,-> where ->group by -> having -> select -> order by -> limit/offset
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
declare M INT;set M = N-1;RETURN (# Write your MySQL query statement below.select distinct salary from Employee order by salary desclimit M, 1 );
END