PLSQL 的简单命令之二

--1.  查询工资大于12000的员工姓名和工资
select first_name,last_name,salary from employees where salary > 12000

--2.    查询员工号为176的员工的姓名和部门号
select first_name,last_name,department_id from employees where job_id = ‘176‘

--3.    选择工资不在5000到12000的员工的姓名和工资
select first_name,last_name,salary from employees where salary < 5000 and salary > 12000

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

--5.    选择在20或50号部门工作的员工姓名和部门号
select first_name,last_name,department_id from employees where department_id in (20,50)

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

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

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

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

--10.    选择姓名中有字母a和e的员工姓名
select first_name,last_name from employees where  lower(first_name) like ‘%a%‘and
lower(first_name) like ‘%e%‘ or lower(last_name)like ‘%a%‘ and lower(last_name)like ‘%e%‘;

--单行函数
--1.    显示系统时间(注:日期+时间)
select sysdate from dual

--2.    查询员工号,姓名,工资,以及工资提高百分之20%后的结果(new salary)
select employee_id,first_name,last_name,salary,salary*1.2 as "NEW SALARY" from employees

--3.    将员工的姓名按首字母排序,并写出姓名的长度(length)
select  substr(first_name,1,1) as FIRSTWORD, length(first_name) as "LENGTH" from employees
order by substr(first_name,1,1) asc

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

--5.    查询员工的姓名,以及在公司工作的月份数(worked_month),并按月份数降序排列
select first_name,last_name,round( months_between(sysdate,hire_date))WORKED_MONTHS from employees
 order by WORKED_MONTHS desc
/*6.    做一个查询,产生下面的结果
<last_name> earns <salary> monthly but wants <salary*3>
Dream Salary
King earns $24000 monthly but wants $72000
*/
select last_name || ‘ earns ‘||salary||‘ monthly but wants ‘||salary*3 as "A GREAT DREAM" from employees

/*7.    使用decode函数,按照下面的条件:
job                  grade
AD_PRES            A
ST_MAN             B
IT_PROG             C
SA_REP              D
ST_CLERK           E
产生下面的结果
Last_name    Job_id    Grade
king    AD_PRES    A
*/
select Last_name||‘ ‘||job_id||‘ ‘||decode(job_id,‘AD_PRES‘,‘A‘,
                                                  ‘ST_MAN‘,‘B‘,
                                                  ‘IT_PROG‘,‘C‘,
                                                  ‘SA_REP‘,‘D‘,
                                                  ‘ST_CLERK‘,‘E‘)
 ||‘ king    AD_PRES    A‘ as SOMEWORDS from employees

--8.    将第7题的查询用case函数再写一遍。
select Last_name||‘ ‘||job_id||‘ ‘||case job_id when ‘AD_PRES‘ then ‘A‘
                                                when ‘ST_MAN‘ then ‘B‘
                                                when ‘IT_PROG‘ then ‘C‘
                                                when ‘SA_REP‘ then ‘D‘
                                                when ‘ST_CLERK‘ then ‘E‘
                                                else ‘ ‘
                                                end
 ||‘ king    AD_PRES    A‘ as SOMEWORDS from employees
时间: 2024-08-05 16:30:53

PLSQL 的简单命令之二的相关文章

PLSQL 的简单命令之三

-- 查找两个表中ID相等的 select a.id, a.name,b.math from stu a,scores b where a.id = b.id -- 右外连接 select b.id, a.name,b.math from stu a,scores b where a.id(+) = b.id select b.id, a.name,b.math from stu a right outer join scores b on a.id = b.id -- 左外连接 select

PLSQL 的简单命令之五

--1. 查询和Zlotkey相同部门的员工姓名和雇用日期 select a.last_name,a.hire_date ,b.department_name from employees a,departments b where b.department_name in (select department_name from departments, employees where last_name = 'Zlotkey') --2. 查询工资比公司平均工资高的员工的员工号,姓名和工资.

PLSQL 的简单命令之四

-- 子查询 -- in 等于表中的任意一个 select * from Stu where id in (select id from scores) -- 和子查询返回结果中的某一个值比较成立即可 select * from scores where id > all (select id from stu ) -- 和子查询返回结果中的所有值比较 select * from scores where id > any (select id from stu ) select * from

五大Linux简单命令解决系统性能问题

五大Linux简单命令解决系统性能问题 2010-12-17 10:07 James Turnbull TechTarget中国 字号:T | T 管理Linux主机的性能看起来经常象是在变魔术一样.许多管理员在遇到性能问题的时候常常简单化处理,依靠硬件的更新换代,更大的内存和更强的CPU来解决问题.事实上,利用一些简单的命令,可以发现许多管理主机的细节问题并且能迅速而简单地解决性能问题. AD:2014WOT全球软件技术峰会北京站 课程视频发布 管理Linux主机的性能看起来经常象是在变魔术一

linux运维自动化之puppet简单应用(二)

上篇博客介绍了在单机环境下的puppet应用,这次我们基于C/S模式来介绍下puppet! 一.实验环境 服务器角色 IP地址 安装软件 主机名 服务器端 172.16.8.1 puppet-server www.gulong.com 客户机端 172.16.8.2 puppet node1.gulong.com 客户机端 172.16.8.3 puppet node2.gulong.com 三台主机时间同步: #ntpdate 172.16.0.1 三台主机可以相互解析: # vim /etc

Apache 的搭建及vim的简单命令

一. vim 简单命令 pwd     当前路径 ls    当前路径所有目录 cd  目录地址   跳转到指定目录 /xxx  查找xxx x 删除当前字符 n 执行上一次查找 二.为什么使用apache 服务器 能够有一个测试的服务器,不是所有的特殊网络服务都能找到免费的!,有些特殊的服务器功能,Apache都能很好的支持 三.安装配置apache 服务器 1.给自己的电脑设置成服务器 2.电脑设置密码,要不别人也可以访问我的电脑. 3.显示mac隐藏文件  defaults write c

Kafka学习(一)配置及简单命令使用

一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,其中涉及到的相关概念如下: Kafka中传递的内容称为message(消息),message 是通过topic(话题)进行分组的 topic 和message 的关系是一对多的关系 我们称发布message的进程为producer ,就是说producer生成<topic->message>对然后 丢进kafka集群 相对应的称订阅topic处理对应message的进程为consumer Kafka集群

lua学习笔记10:lua简单命令行

前面多次用了命令行,这次就好好学下命令行: 一 格式 lua [options][script][args] 二 具体命令 -e 直接将命令传个lua -l 加载一个文件 -i 进入交互模式 例如,终端输入: lua -e "print(math.sin(12))" lua学习笔记10:lua简单命令行,布布扣,bubuko.com

Bind简单应用之二(正向解析主从服务器)

DNS主从服务器应用实验 实验环境    系统:Centos 6.3 X64 软件:Bind.x86_64 32:9.8.2-0.10.rc1.el6 主服务器: IP 10.0.0.101:netmask 255.255.255.0 :DNS 10.0.0.102:GW 10.0.0.1 从服务器: IP 10.0.0.102:netmask 255.255.255.0 :DNS 10.0.0.102:GW 10.0.0.1 1.分别在两台服务器上安装Bind软件 #yum install b