ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

【MySQL】MySQL从0到0.9 - 持续更新ing

【MySQL】MySQL从0到0.9 - 持续更新ing

MySQL

SQL 基础

sql执行顺序

DDL 语句

show databases;
show tables;
desc table_name; # 获取表信息
show create table 表名; // 查询指定表的建表语句 

DDL
修改表结构
修改字段

数据类型

整型
字符型
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
返回列表