目录


desc 表名
desc t_mysql_employees;

INSERT into 表名(列名) values(要插入列的数据);
INSERT into t_mysql_employees(first_name,last_name,email,phone_number,salary,commission_pct,manager_id,hiredate) values('oy','x','1828190940@qq.com','155********',3000,0.25,100,now());
我们现在看下总共有多少行

可以看到,比之前要多一行了。
试一下查询它,看能不能查到。
select *from 表名 / select *from 表名 where 查询条件
- select *from t_mysql_employees where phone_number='155********'
-
- select *from t_mysql_employees;
修改update 表名 set 要修改数据的列名=修改后的数据 where 条件
update t_mysql_employees set last_name='xiang' where phone_number='155********'
再查询一下是否修改成功

delete from 表名 where 条件语句
delete from t_mysql_employees where phone_number='155********'
再查询一下

查询不到,已经删除掉了。
案例1:查询工资>12000的员工信息
select * from t_mysql_employees where salary>12000;
案例2:查询部门编号不等于90号的员工名和部门编号
select last_name,department_id from t_mysql_employees where not(department_id=90);

案例1:查询工资z在10000到20000之间的员工名、工资以及奖金
select last_name,salary,commission_pct from t_mysql_employees where salary between 10000 and 20000;

案例2:查询部门编号不是在90到110之间,或者工资高于15000的员工信息
select * from t_mysql_employees where not(department_id between 90 and 110) or salary>15000;

like
案例1:查询员工名中包含字符a的员工信息
select * from t_mysql_employees where last_name like '%a%'

案例2:查询员工名中第三个字符为e,第五个字符为a的员工名和工资
select * from t_mysql_employees where last_name like '%e%a%';

案例3:查询员工名中第二个字符为_的员工名

between and
查询员工编号在100到120之间的员工信息
select * from t_mysql_employees where employee_id between 100 and 120;

in
查询员工的工种编号是 IT_PROG、AD_VP、AD_PRES中的一个员工名和工种编号
select last_name,job_id from t_mysql_employees where job_id in ('IT_PROG','AD_VP','AD_PRES');

is null
查询没有奖金的员工名和奖金率
select last_name,commission_pct from t_mysql_employees where commission_pct is not null;

安全等于 <=>
查询工资为12000的员工信息
SELECT * FROM t_mysql_employees where salary <=> 12000;

IS NULL:仅仅可以判断NULL值,可读性较高,建议使用
<=> :既可以判断NULL值,又可以判断普通的数值,可读性较低
select * from t_mysql_employees ORDER BY salary;

查询部门编号>=90的员工信息,并按员工编号降序
select * from t_mysql_employees where department_id>=90 ORDER BY employee_id desc;

查询员工信息 按年薪降序

查询员工信息 按年薪升序
SELECT em.salary*12*(1+IFNULL(commission_pct,0)),em.* FROM t_mysql_employees em ORDER BY em.salary*12*(1+IFNULL(commission_pct,0))

查询员工名,并且按名字的长度降序
SELECT last_name,COUNT(first_name,last_name),LENGTH(CONCAT(first_name,last_name)) from t_mysql_employees ORDER BY LENGTH(CONCAT(first_name,last_name)) desc;

查询员工信息,要求先按工资降序,再按employee_id升序
select * from t_mysql_employees ORDER BY salary desc,employee_id asc;

查询员工的姓名和部门号和年薪,按年薪降序 按姓名升序
SELECT first_name,last_name,department_id,salary*12*(1+IFNULL(commission_pct,0)) from t_mysql_employees ORDER BY salary*12*(1+IFNULL(commission_pct,0)) desc,first_name asc,last_name asc;

选择工资不在8000到17000的员工的姓名和工资,按工资降序
select first_name,last_name,salary from t_mysql_employees where not(salary between 8000 and 17000) ORDER BY salary desc;

查询邮箱中包含e的员工信息,并先按邮箱的字节数降序,再按部门号升序
select * from t_mysql_employees em where email like '%e%' ORDER BY department_id asc,LENGTH(email) desc;

OK,今日的学习就到此结束啦,如果对个位看官有帮助的话可以留下免费的赞哦(收藏或关注也行),如果文章中有什么问题或不足以及需要改正的地方可以私信博主,博主会做出改正的。个位看官,小陽在此跟大家说拜拜啦!