标签:image trunc jpg mon min group 查询 where sysdate
1.查询员工的姓名和日工资(保留1位小数);
select ename,round(sal/30,1)
from emp;
2.查询并显示部门号为01和02的所有员工的姓名首字及岗位;
select substr(ename,0,1), job
from emp
where deptno = ‘01‘ or deptno = ‘02‘;
3.查询并显示所有员工的姓名及工龄;
select ename,trunc(months_between(sysdate,hiedate)/12)
from emp;
4.查询1990年6月5号以前入职的员工姓名和岗位;
select ename,job
from emp
where hiedate < to_date('1990-06-5','yyyy-mm-dd');
5.查询1990年入职的员工姓名和入职日期 (使用EXTRACT、TO_DATE分别实现);
select ename,hiedate
from emp
where extract(year from hiedate) = '1990'
select ename , hiedate
from emp
where hiedate >= to_date('1990-01-01','yyyy-mm-dd') and hiedate <= to_date
('1990-12-31','yyyy-mm-dd')
6.查询6月份入职的员工姓名和入职日期;
select ename,hiedate
from emp
where extract(month from hiedate) = '06'
1.统计员工总人数;
select count(empno)
from emp
2.员工人数在2人及以上的部门和人数;
select count(ename)人数,job
from emp
group by job
having count(ename)>1
3.查询所有员工的薪水总额、平均薪水、最高薪水及最低薪水;
select sum(sal),avg(sal),max(sal),min(sal)
from emp
4.查询’02’部门员工的薪水总额、平均薪水、最高薪水及最低薪水;
select sum(sal),avg(sal),max(sal),min(sal)
from emp
where deptno = '02'
5.查询各个部门的员工人数及平均奖金;
select count(ename)人数,job 部门,avg(comn)平均奖金
from emp
group by job
6.统计男员工的人数;
select count(ename) 人数
from emp
where sex = '男'
7.统计男、女员工的人数;
select count(ename) 人数
from emp
group by sex
8.统计部门编号为01和02两部门的男、女员工的人数;
select count(sex)
from emp
where deptno = '01'or '02'
group by sex
标签:image trunc jpg mon min group 查询 where sysdate
原文地址:http://www.cnblogs.com/yjlblog/p/7833849.html