MySQL查询语句

基本查询语句

DISTINCT 查找唯一值 实例:SELECT DISTINCT title FROM lagou_all

BETWEEN ADN 范围内 SELECT title,salary FROM lagou_all WHERE salary BETWEEN 6000 AND 20000
NOT BETWEEN AND 范围外 SELECT title,salary FROM lagou_all WHERE salary NOT BETWEEN 6000 AND 20000

IS NULL 空值查询 SELECT title,salary FROM lagou_all WHERE salary IS NULL
IS NOT NULL 非空值查询 SELECT title,salary FROM lagou_all WHERE salary IS NOT NULL

IN 在集合中查询 SELECT title,salary from lagou_all WHERE title IN ("'java'","'hr'")
NOT IN 不在集合中查询 SELECT title,salary from lagou_all WHERE title NOT IN ("'java'","'hr'") 注意:如果查询集合中存在NULL,不会查询到任何结果

LIKE 模糊匹配查询 SELECT title,salary from lagou_all WHERE title LIKE "'JAVA%'" 注意: %为通配符

ORDER BY 查询结果排序 SELECT title,salary from lagou_all WHERE title LIKE "'JAVA%'" ORDER BY salary 注意: 默认为升序, 末尾添加DESC则为降序

LIMIT 限制查询数量 SELECT title,salary from lagou_all WHERE title LIKE "'JAVA%'" ORDER BY salary LIMIT 1000 注意: 默认从0开始, 可以指定范围

COUNT 查询总数 SELECT COUNT(salary) from lagou_all
MAX MIN 最大值最小值 SELECT MAX(salary),MIN(salary) from lagou_all

GROUP BY 分组查询 SELECT title,salary from lagou_all GROUP BY title 注意: 分组必须有重复值,否则没有意义
GROUP BY 搭配 GROUP_CONCAT 统计分组查询 SELECT title,GROUP_CONCAT(salary) from lagou_all GROUP BY title