码迷,mamicode.com
首页 > 数据库 > 详细

sql 日记

时间:2016-10-14 23:08:14      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:


--4.选择雇用时间在1998-02-01到1998-05-01之间的员工姓名,job_id和雇用时间
select last_name,job_id,hire_date
from employees
where to_char(hire_date,‘yyyy-mm-dd‘) between ‘1998-02-01‘ and ‘1998-05-01‘

--5.选择在20或50号部门工作的员工姓名和部门号
select last_name,department_id
from employees
--where department_id between 20 and 50
where department_id >=20 and department_id <=50

--6.选择在1994年雇用的员工的姓名和雇用时间
select last_name,hire_date
from employees
--where to_char(hire_date,‘yyyy‘)=‘1994‘
where hire_date like ‘%94‘

--7.选择公司中没有管理者的员工姓名及job_id
select last_name,job_id
from employees
where manager_id is null

--8.选择公司中有奖金的员工姓名,工资和奖金级别
select last_name,salary,commission_pct
from employees
where commission_pct is not null

--9.选择员工姓名的第三个字母是a的员工姓名
select last_name
from employees
where last_name = ‘__a%‘

--10.选择姓名中有字母a和e的员工姓名
select last_name
from employees
where last_name like ‘%a%e%‘ or last_name like ‘%e%a%‘

 


1.显示系统时间(注:日期+时间)
select to_char(sysdate,‘yyyy-mm-dd hh:mi:ss‘)
from dual

--2.查询员工号,姓名,工资,以及工资提高百分之20%后的结果(new salary)
select department_id,last_name,salary,salary*(1+0.2) "new salary"
from employee01

--将员工的姓名按首字母排序,并写出姓名的长度(length)
select last_name,length(last_name)
from employee01
order by last_name asc

--4.查询各员工的姓名,并显示出各员工在公司工作的月份数(worked_month)。
select last_name,hire_date,round(months_between(sysdate,hire_date),1) worked_month
from employees

--5.查询员工的姓名,以及在公司工作的月份数(worked_month),并按月份数降序排列
select last_name,hire_date,round(months_between(sysdate,hire_date),1) worked_month
from employees
order by worked_month desc

--6.做一个查询,产生下面的结果
--<last_name> earns <salary> monthly but wants <salary*3>
Dream Salary
-------------------------------------------------------------------
King earns $24240 monthly but wants $72720

select last_name || ‘ earns ‘ || to_char(salary,‘$999999‘) || ‘ monthly but wants ‘ || to_char(salary*3,‘$999999‘) "Dream Salary"
from employees

select last_name "Last_name",job_id "Job_id",decode(
job_id,‘AD_PRES‘,‘A‘,
‘ST_MAN‘,‘B‘,
‘IT_PROG‘,‘C‘,
‘SA_REP‘,‘D‘,
‘ST_CLERK‘,‘E‘) "Grade"
from employees

sql 日记

标签:

原文地址:http://www.cnblogs.com/longc/p/5962028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!