目录
一、SQL高级语句
1.导入文件至数据库
#将脚本导入 source 加文件路径
mysql> source /backup/test.sql;
2. select
显示表格中的一个或者多个字段中所有的信息
#语法:
select 字段名 from 表名;
示例1:
select * from students;
示例2:
select * from students;
3. distinct
查询不重复记录
#语法:
select distinct 字段 from 表名﹔
#示例1:去除年龄字段中重复的
select distinct age from students;
#示例2:查找性别
select distinct gender from students;
4.where
where 有条件的查询
#语法:
select '字段' from 表名 where 条件
#示例:显示name和age 并且要找到age小于20
select name,age from students where age < 20;
5.and;or
and 且 ; or 或
#语法:
select 字段名 from 表名 where 条件1 (and|or) 条件2 (and|or)条件3;
示例1:显示name和age 并且要找到age大于20小于30
select name,age from students where age >20 and age <30;
6.in
显示已知值的资料
#语法:
select 字段名 from 表名 where 字段 in ('值1','值2'....);
#示例1:显示学号为1,2,3,4的学生记录
select * from students where StuID in (1,2,3,4);
#示例2:显示班级为1和3的学生记录
select * from students where ClassID in (1,3);