跳转至

SQL


SELECT 字段, 字段 FROM ;

SELECT * FROM ;

INSERT INTO  (字段, 字段) VALUES (, );

INSERT INTO user VALUES (, );

DELETE FROM 

UPDATE  SET 字段=, 字段=;

条件

链接符号可以是 AND 或 OR

WHERE 字段='值' 链接符号 字段='值';

算术运算符

SELECT * FROM  WHERE 字段 运算符 ;

-- 演示
SELECT * FROM user WHERE age < 20+age;

LIKE

模糊查询, 加在 WHERE 条件后面

% 零个 一个 多个

_ 一个

SELECT * FROM user WHERE 字段 LIKE '%值%';

GLOB

匹配, 加在 WHERE 条件后面, 大小写敏感

*    零个 一个 多个

?    一个
SELECT * FROM  WHERE 字段 GLOB '值*';

LIMIT

设置返回的数量

SELECT * FROM  LIMIT 2

返回数量 与 截取位置

SELECT * FROM  LIMIT 2 OFFSET 2;

排序

默认升序

SELECT * FROM  ORDER BY 字段, 字段;

降序 DESC

SELECT * FROM  ORDER BY 字段 DESC, 字段 DESC;

DISTINCT

重复数据只返回一条

SELECT DISTINCT 字段, 字段 FROM 

子查询

() 里面查询出来的值作为条件

SELECT * FROM  WHERE 字段 IN (, );

演示 查

SELECT * FROM user WHERE age = (SELECT age FROM user WHERE name GLOB '小*');

演示 改

UPDATE user SET age = age * 0.50 
WHERE age IN (SELECT age FROM user
WHERE age >= 27);

演示 删

DELETE FROM user
WHERE age IN (SELECT date FROM holiday
WHERE date > 27);