MySQL 查询数据
1.MySQL 的基本查询
1.MySQL 的列选择
SELECT * | 投影列 FROM 表名
查询 departments 表中的所有数据
select * from departments;
2.MySQL 的行选择
SELECT * | 投影列 FROM 表名 WHERE 选择条件
查询 departments 表中部门 ID 为 4 的部门名称与工作地点 ID。
select department_name,location_id from departments where department_id =4;
3.SELECT 语句中的算术表达式
加法运算:+
减法运算:-
乘法运算:*
除法运算,返回商 :/
求余运算,返回余数:%
计算 employees 表中的员工全年薪水加 100 以后的薪水是多少?
select employees_id,last_name,email,12*salary+100 from employees;
4.MySQL 中定义空值
包含空值的算术表达式计算结果为空。
在 employees 中添加 commission_pct,计算年薪包含佣金。
alter table employees add column commission_pct float(5,2);
select 12*salary*commission_pct from employees;
5.MySQL 中的列别名
SELECT 列名 AS 列别名 FROM 表名 WHERE 条件
查询 employees 表将雇员 laser_name 列名改为 name。
select last_name as name from employees;
6.MySQL 中的连字符
MySQL 中并不支持||作为连字符,需要使用 concat 函数。在参数数量上与 oracle 的