1.单行函数
1.显示系统时间(注:时间+日期)
select now();
2.查询员工号,姓名,工资,以及工资提高20%之后的结果(new salary)
select employee_id,last_name,salary,salary*1.2 as 'new salary' from employees;
3.将员工的姓名按首字母排序,并写出姓名的长度
select last_name,length(last_name) from employees order by substr(last_name,1,1) asc;
4.做一个查询,产生下面的结果
<last_name> earns monthly but wants <salary*3>
Dream salary
K_ing earns 24000 monthly but wants 72000
select concat(last_name,'earns',salary,'monthly but wants',salary*3) as 'Dream salary' from employees where last_name = 'K_ing';
5.使用case-when ,按照下面的条件
job grade
ad_pres A
st_man B
it_prog C
sa_red D
st_clerk E
产生下面的结果
last_name job_id grade
king ad_pres A
select job_id as job,
case job_id
when 'ad_pres' then 'A'
when 'st_man' then 'B'
when 'it_prog' then 'C'
when 'sa_red' then 'D'
when 'st_clerk' then 'E'
end as grade
from employees
where job_id = 'ad_pres';
2.分组函数
1.查询公司员工工资的最大值,最小值,平均值,总和
select max(salary)最大值,min(salary) 最小值,avg(salary) 平均值,sum(salary) 总和,count(salary) 个数 from employees;
2.查询员工表中的最大入职时间和最小入职时间的相差天数(diffrence)
注:datediff()函数查询日期之间间隔。ps select datediff(now(),'1997-9-27');
select datediff(max(hiredate),min(hiredate)) as diffrence from employees;
3.查询部门编号为90的员工个数
select count(*) from employees where department_id = 90;