1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| 1. select * from table_name [where 条件1 and 条件2 or 条件3 and not 条件4]; 2. select 字段名1, 字段名2,... from table_name [where 条件1 and 条件2 or 条件3 and not 条件4]; 3. select table_name.字段名1, table_name.字段名2,... from table_name [where 条件1 and 条件2 or 条件3 and not 条件4]; 4. select tn.字段名1, tn.字段名2,... from table_name as tn [where 条件1 and 条件2 or 条件3 and not 条件4]; 5. select 字段名1 as 别名, 字段名2 as 别名,... from table_name [where 条件1 and 条件2 or 条件3 and not 条件4]; 6. select distinct * from table_name [where 条件1 and 条件2 or 条件3 and not 条件4]; 7. select * from table_name [where 条件1 and 条件2 or 条件3 and not 条件4]; 8. select * from table_name where 字段名 like "%关%键%字%"; 9. select * from table_name where 字段名 rlike 正则表达式; 10. select * from table_name where 字段名 [not] in (值1, 值2, ...); 11. select * from table_name where 字段名 [not] between ... and ...; 12. select * from table_name where 字段名 is [not] null; 13. select * from table_name [where 条件] order by 字段名1 [, 字段名2, ...] [asc(默认)/desc] 14. select count(字段名) from table_name [where 条件]; select max(字段名) from table_name [where 条件]; select min(字段名) from table_name [where 条件]; select avg(字段名) from table_name [where 条件]; select sum(字段名) from table_name [where 条件]; select round(xxx.xxx, y) from table_name [where 条件]; 15. select 聚合函数, 分组字段/分组条件 from table_name [where 条件] group by 分组字段/分组条件; select 分组字段/分组条件, group_concat(字段名1, [, 分隔符,] 字段名2, ...) from table_name [where 条件] group by 分组字段/分组条件; 16. select 分组字段/分组条件, ... from table_name [where 条件] group by 分组字段/分组条件 having 条件(集合函数条件或其他条件) 17. select * from table_name [where 条件] limit [0, ] x个数; 18. - 内连接查询 : 查询结果是两个表匹配到的数据 : (表名1 inner join 表名2 on 条件) - 右连接查询 : 查询结果是两个表匹配到的数据,右表特有的数据,对于左边不存在的数据使用null填充 : (表名1 right join 表名2 on 条件) - 左连接查询 : 查询结果是两个表匹配到的数据,左表特有的数据,对于右边不存在的数据使用null填充 : (表名1 left join 表名2 on 条件)) } select * from 表1 inner join 表2 on 两个表的字段连接条件 [having 条件] [order by 条件]; select * from 表1 left join 表2 on 两个表的字段连接条件 [having 条件] [order by 条件]; 19. 子查询: 使用子查询的结果作为父查询的条件查询 select * from table_name where 字段名/条件=(select xxx from table_name where 条件);
|