标签:平均工资 manage null nbsp from rom ddr student str
# 去重复字段
#select distinct name,address from student
# 列运算
#select name , age+1 as age from student
# null运算
#select ifnull(address,0) + 1 as address from student
# 字符串相加
#select concat(address, ‘str‘) as address from student
select * from dept ;
select * from emp ;
select * from stu ;
select * from emp where job = ‘manager‘;
select * from emp where job != ‘manager‘;
select * from emp where job <> ‘manager‘;
select ename,job from emp where sal > 20000;
select * from emp where sal < 10000;
select * from emp where sal between 10000 and 20000;
select * from emp where mgr in (1004,1009);
select * from emp where mgr = 1004 or mgr = 1009 ;
select * from emp where comm is null ;
select * from emp where comm is not null ;
select * from emp where mgr = 1009 and sal > 20000 ;
# 以z开头并且有8个字符长即可
select * from emp where ename like ‘z_______‘;
# 以z开头的数据
select * from emp where ename like ‘z%‘ ;
# 查询姓名中包含z
select * from emp where ename like ‘%z%‘;
# 员工信息按薪水从高到低排列
select ename,sal from emp order by sal desc ;
# 升续 : 从低到高排列
select ename,sal from emp order by sal asc ;
# 默认排序规则 asc
select ename,sal from emp order by sal ;
select ename,sal,comm from emp order by sal asc ,comm desc ;
# 不为null的记录数
select count(*) as mgr from emp;
SELECT COUNT(comm), COUNT(mgr) FROM emp;
select sum(sal) from emp where sal > 20000;
select avg(sal) from emp ;
select max(sal) max , min(sal) min from emp;
select count(*) as ‘公司人数‘ , sum(sal) as ‘最高工资‘
from emp;
select min(sal) ,job as ‘岗位‘ from emp group by job ;
# 平均工资大于20000人数小于3 的工种数据
select job, count(*) from emp group by job having count(*) < 3;
# emp 表中的前10 行数据
select * from emp limit 0,10;
# emp 表中工资前5名
select * from emp order by sal desc limit 0,5;
# emp 表工资为6 ~ 10 名
select * from emp order by sal desc limit 5,5;
# 去重复字段
#select distinct name,address from student
# 列运算
#select name , age+1 as age from student
# null运算
#select ifnull(address,0) + 1 as address from student
# 字符串相加
#select concat(address, ‘str‘) as address from student
select * from dept ;
select * from emp ;
select * from stu ;
select * from emp where job = ‘manager‘;
select * from emp where job != ‘manager‘;
select * from emp where job <> ‘manager‘;
select ename,job from emp where sal > 20000;
select * from emp where sal < 10000;
select * from emp where sal between 10000 and 20000;
select * from emp where mgr in (1004,1009);
select * from emp where mgr = 1004 or mgr = 1009 ;
select * from emp where comm is null ;
select * from emp where comm is not null ;
select * from emp where mgr = 1009 and sal > 20000 ;
# 以z开头并且有8个字符长即可
select * from emp where ename like ‘z_______‘;
# 以z开头的数据
select * from emp where ename like ‘z%‘ ;
# 查询姓名中包含z
select * from emp where ename like ‘%z%‘;
# 员工信息按薪水从高到低排列
select ename,sal from emp order by sal desc ;
# 升续 : 从低到高排列
select ename,sal from emp order by sal asc ;
# 默认排序规则 asc
select ename,sal from emp order by sal ;
select ename,sal,comm from emp order by sal asc ,comm desc ;
# 不为null的记录数
select count(*) as mgr from emp;
SELECT COUNT(comm), COUNT(mgr) FROM emp;
select sum(sal) from emp where sal > 20000;
select avg(sal) from emp ;
select max(sal) max , min(sal) min from emp;
select count(*) as ‘公司人数‘ , sum(sal) as ‘最高工资‘
from emp;
select min(sal) ,job as ‘岗位‘ from emp group by job ;
# 平均工资大于20000人数小于3 的工种数据
select job, count(*) from emp group by job having count(*) < 3;
# emp 表中的前10 行数据
select * from emp limit 0,10;
# emp 表中工资前5名
select * from emp order by sal desc limit 0,5;
# emp 表工资为6 ~ 10 名
select * from emp order by sal desc limit 5,5;
MySQL 语句代码
标签:平均工资 manage null nbsp from rom ddr student str
原文地址:http://www.cnblogs.com/xuewuzhijing95hao/p/7199651.html