--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