文章目录
进阶1. 直接查询
– 查询表中的单个字段 –
select sNo from student;
– 查询表中的单个字段 –
select sNo, sName from student;
– 查询表中的所有字段
select * from student;
注意: 查询所有字段的时候 要使用哪个库 use xxx
2. 查询常量值
select 100; select '男';
3. 查询表达值
select 100%98;
4. 查询函数
select version();
5. 为字段起别名
1. 方便理解
2. 方便区分 (如果要查询的字段有重名的情况下,可以区分看来看)
方法一
select 100%98 as 结果;
select sNo as 学号, sName as 名字 from student; #提高可读性
方法二
select sNo 学号, sName 名字 from student;
– 特殊情况 想把sNo 起为 out put 的别名 –
select sNo as out put from student; – err 因为 out 也是一个关键字。–
select sNo as ‘out put’ from student;
8. 去重 查询学生表中涉及到的所有班级
select distinct deptment from student;
9. ‘+’ 号的作用 查询学生名字和班级 连接成一个字段
C语言中 ‘+’ 号的作用:
1. 运算符,两个操作数都为数值型
2. 连接符, 只要有一个操作数为字符串
Mysql 中 :
仅仅只有一个功能: 运算符
select 100+90; # 两个都为数值型 运算结果 190
select '123'+90; # 有一方为字符型,试图将字符型转换成数