1 插入数据
2 insert into tab1(name,age) values('alex',18),('jack',19);
3 insert into tab1(name,age) select name age from tab2;
4 select name,age from tab1 where id between 5 and 12;
5 select name,age from tab1 where id not in (1,3,5);
6 select name,age from tab1 where id<1 and id>2 or id>4;
7 模糊匹配
8 select name,age from tab1 where name like 'a%';
9 select age from tab1 where name like 'a_';
10 查询条数限制
11 select age from tab1 limit 10 offset 100; /*从第100条开始取10个*/
12 select age from tab1 limit 4,5; /*从第4条开始取5条*/
13 select age from tab1 limit 5;/*取前5条数据*/
14 排序
15 select age from tab1 order by id asc,name desc;
16 分组
17 select depart_id,count(id) from userinfo group by depart_id;
18 count() max() min() avg() sum()聚合函数
19 对于聚合函数结果进行二次筛选 必须使用having
20 select depart_id,count(id) from userinfo group by depart_id having count(id)>1;
21
22 连表操作
23 select * from tab1,tab2 where tab1.id = tab2.id;
24 select name,grade from tab1 left join tab2 on tab1.id = tab2.id;
25 //tab1信息会全部显示
26 select name,grade from tab1 right join tab2 on tab1.id = tab2.id;
27 //tab2信息会全部显示
1 select name,grade from tab1 inner join tab2 on tab1.id = tab2.id;
2 //将出现null时的行隐藏
1 //导出sql文件 数据表结构+数据
2 mysqldump -u root db1 > db1.sql -p
3 //导出sql文件 数据表结构
4 mysqldump -u root -d db1 > db2.sql -p
5 //导入sql文件
6 mysqldump -u root -d db1 < db1.sql -p