WHWRE子句
USE world; -- 选中数据库,选中加粗
SELECT * FROM city -- 查询表中所有数据
SELECT * FROM city WHERE ID = 1; -- 显示表中某行
SELECT DISTINCT Population AS new FROM city; -- 显示表中某列
-- 如果新名字有空格,需要用引号
-- DISTINCT可以去重
-- AS可以省略
IN运算符
USE world;
SELECT * FROM country
WHERE Code IN ('ABW','AFG')
-- 等价于WHERE Code = 'ABW' OR Code = 'AFG'
BETWEEN运算符
USE world;
SELECT * FROM country
WHERE Population BETWEEN 100000 AND 110000
-- 等同于WHERE Population >= 100000 AND Population <= 110000
LIKE运算符
两种通配符
%
任何个数的字符_
单个字符
USE world;
SELECT * FROM country
WHERE Name LIKE 'Arub%' / 'A___a'
REGEXP运算符
- ^ 开头
- $ 结尾
- [a-h] 含a-g中任一一个
使用与LIKE相同
USE world;
SELECT * FROM country
WHERE Name REGEXP 'Arub'
IS NULL运算符
USE world;
SELECT * FROM country
where Population is null/is not null
ORDER BY子句
USE world;
SELECT * FROM country
ORDER BY LifeExpectancy,Region DESC
-- DESC表示降序
-- 可包括任何列 可包括没选择的列
-- 任何一个排序依据列后面都可选加 DESC
LIMIT子句
USE world;
SELECT * FROM country
limit 3 / 30000 / 6, 3
-- 6,3 表示跳过前6个,取第7~9个,6是偏移量