以下查询练习以下表emp(人员表)和dept(部门表)为例
MySQL子查询。查询出所有员工的编号和姓名
select eid,ename from emp;
查询出所有员工的姓名、生日、工资
select ename,birthday,salary from emp;
select eid,ename,sex,birthday,salary,deptId from emp;
select * from emp;
查询出所有员工的编号和姓名,使用汉字别名
select eid as 编号,ename as 姓名 from emp;
Mysql查询,查询出所有员工的姓名、性别、生日、工资,使用一个字母作为别名
select ename a,sex b,birthday c,salary d from emp;
tip:as关键字可以省略,保留即可。
查询出都有哪些性别的员工
select distinct sex from emp;
查询出员工都分布在哪些部门
select distinct deptId from emp;
计算 1+3+5+87.4+54.39
select 1+3+5+8*7.4+5*4.39;
简单选择排序,查询出所有员工的姓名及其年薪
select ename,salary*12 from emp;
假设每个员工的工资增长1000,年终奖20000,查询出所有员工的姓名及其年薪,使用汉字别名
select ename 姓名,(salary+1000)*12+20000 年薪 from emp;
查询出所有的部门,结果按照部门编号升序排列
select * from dept order by did asc;
查询出所有的部门,结果按照部门编号降序排列
select * from dept order by did desc;
MySQL查看数据库,查询出所有的员工,结果按照工资降序排列
select * from emp order by salary desc;
查询出所有的员工,结果按照年龄从大到小排列(生日从小到大)
select * from emp order by birthday asc;
查询出所有的员工,结果按照姓名的升序排列
select * from emp order by ename;
tip:按照字符串排序是按照字符的编码排列
不加排序规则,默认是按照升序排列
查询出所有的员工,结果按照工资的升序排列,要求男员工显示在前女员工显示在后
select * from emp order by sex desc, salary;
MySQL查看表命令、查询出所有的员工,结果按照部门升序排列,如果部门相同按照年龄从小到大排列(生日越小年龄越大)
select * from emp order by deptId,birthday desc;
查询出编号为5的员工所有列
select * from emp where eid=5;
查询出姓名为king的员工所有列
select * from emp where ename='king';
查询出20号部门下的员工有哪些
select * from emp where deptId=20;
MySQL查询语句?查询出工资在6000以上的员工有哪些
select * from emp where salary>6000;
and (&&) 并且,两个条件都满足
or (||) 或者,两个条件满足其一
is null 值为null
is not null 值不为null
in( ) 满足其中一个
not in( ) 都不满足
select * from emp where deptId!=20;
查询出没有明确部门的员工有哪些
select * from emp where deptId is null;
最简单的php代码示例,查询出有明确部门的员工有哪些
select * from emp where deptId is not null;
查询出工资在7000以上的男员工有哪些
select * from emp where salary>7000 and sex=1;
select * from emp where salary>7000 && sex=1;
a not between and b 不在a~b之间
查询出工资在6000~9000直接的员工有哪些
g代码程序简单示例,select * from emp where salary>=6000 && salary<=9000;
select * from emp where salary between 6000 and 9000;
查询出工资在6000以下或者9000以上的员工有哪些
select * from emp where salary<6000 or salary>9000;
select * from emp where salary<6000 || salary>9000;
select * from emp where salary not between 6000 and 9000;
查询出1993年出生的员工有哪些
select * from emp where birthday>='1993-1-1' && birthday<='1993-12-31';
select * from emp where birthday between '1993-1-1' and '1993-12-31';
MySQL查看表结构。查询出20号部门或者30号部门的员工有哪些
select * from emp where deptId=20 || deptId=30;
select * from emp where deptId in(20,30);
查询出不在20号部门并且不在30号部门的员工有哪些
select * from emp where deptId!=20 && deptId!=30;
select * from emp where deptId not in(20,30);
%——匹配任意个字符 >=0
_ ——任意一个字符 =1
查询出姓名中含有字母o的员工有哪些
select * from emp where ename like '%o%';
查询出姓名中以o结尾的员工有哪些
select * from emp where ename like '%o';
查询出姓名中第二个字符是o员工有哪些
select * from emp where ename like '_o%';
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态