1)显示正好为5个字符的员工的姓名
HR@ORA11GR2>select last_name,first_name from employees
2 where length(first_name) = 5;
2)显示不带有"R"的员工的姓名.
HR@ORA11GR2>select last_name,first_name from employees
2 where first_name not like '%R%';
3)显示所有员工的姓名,用a替换所有"A"
HR@ORA11GR2>select replace (first_name,'A','a') from employees;
4)显示所有员工的姓名、工作和薪金,按工作的降序排序,若工作相同则按薪金排序
HR@ORA11GR2>select last_name,first_name,job_id,salary from employees
2 order by job_id desc,salary; 5)显示在一个月为30天的情况所有员工的日薪金,忽略余数.
HR@ORA11GR2>select last_name,first_name,trunc(salary/30) daysal from employees; 6)找出员工名字中含有a和e的
HR@ORA11GR2>select distinct(first_name) from employees
2 where first_name like '%a%' and first_name like '%e%';
7)select语句的输出结果格式如下:
select * from hr_departments;
select * from hr_emp;
select * from hr_region;
…….
Departments是表名,可以查询tab
HR@ORA11GR2>select 'select * from '||'hr_'||tname||';' as select_from_hr_table from tab where tabtype='TABLE'; 7)要求基本工资大于1500,同时可以领取奖金的雇员信息
HR@ORA11GR2>select * from employees
2 where salary > 1500 and commission_pct is not null;
8)要求显示所有雇员的姓名及姓名的后3个字符
HR@ORA11GR2>select first_name,substr(first_name,-3,3) from employees; 9)求出每个雇员的年薪(应算上奖金)注意处理Null值
HR@ORA11GR2>select last_name,first_name,(salary+salary*nvl(commission_pct,0))*12 yearsal from employees;
10)以年月日方式显示所有员工的受聘日期。
HR@ORA11GR2>select last_name,first_name,to_char(hire_date,'yyyy-mm-dd')
2 from employees;
11)用concat显示所有员工的姓名全称
HR@ORA11GR2>select concat (first_name || chr(32),last_name) from employees;
12)显示所有员工姓名(last_name)倒数第三个字符。
HR@ORA11GR2>select first_name,substr(first_name,-3,1) ename from employees;
13)Hr用户下拼接sql显示如下格式内容:注:index_name字段可以从user_indexes中查询
Alter index “index_name” rebuild; HR@ORA11GR2>select 'alter index '||index_name||' rebuild' from user_indexes; 15)查员工表显示如下信息:年终奖是工资+奖金
部门号 姓名 年终奖 HR@ORA11GR2>Select department_id,first_name,last_name,(salary+salary*nvl(commission_pct,0)) commission from employees; 16)显示整个公司的最高工资、最低工资、工资总和、平均工资,保留到整数位。
HR@ORA11GR2>select max(nvl(salary,0)) maxsal,min(nvl(salary,0)) minsal,sum(nvl(salary,0)) sumsal,trunc(avg(nvl(salary,0))) avgsal
2 from employees; MAXSAL MINSAL SUMSAL AVGSAL
---------- ---------- ---------- ----------
24000 2100 691416 6461
17)哪些部门的人数比32号部门的人数多
SCOTT@ORA11GR2>select deptno,count(empno)
2 from emp
3 group by deptno
4 having count(empno) > (select count(empno) from emp where deptno = 10);
18)查询出比7654工资要高的全部雇员的信息
SCOTT@ORA11GR2>select * from emp
2 where sal > (select sal from emp where empno = 7654);
19)要求查询工资比7654高,同时与7788从事相同工作的全部雇员
SCOTT@ORA11GR2>select * from emp
2 where sal > (select sal from emp where empno = 7654)
3 and deptno in (select deptno from emp where empno = 7788); 20)哪些员工的工资,高于整个公司的平均工资,列出员工的名字和工资(降序)
HR@ORA11GR2>select last_name,first_name,salary from employees
2 where salary > (select avg(salary) from employees)
3 order by salary desc;
21)列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门。
SCOTT@ORA11GR2> select a.dname,b.empno,b.ename,b.job,b.mgr,b.hiredate,b.sal,b.deptno
2 from dept a left join emp b on a.deptno=b.deptno;
22)查询每个员工的领导是谁(自连接)。
SCOTT@ORA11GR2>select a.ename as clerk,b.ename as boss from emp a,emp b where a.mgr=b.empno;
23)要求查询雇员的编号、姓名、部门编号、部门名称及部门位置
SCOTT@ORA11GR2>select e.empno,e.ename,d.deptno,d.dname,d.loc from emp e,dept d where e.deptno=d.deptno;

【考试】简单的sql语句的更多相关文章

  1. [20190328]简单探究sql语句相关mutexes.txt

    [20190328]简单探究sql语句相关mutexes.txt --//摘要:http://www.askmaclean.com/archives/understanding-oracle-mute ...

  2. 四种简单的sql语句(增删改查语句)

    四种简单的sql语句(增删改查语句) 一.插入语句 insert into [table] ([column],[column],[column]) values(?,?,?) 二.删除语句 dele ...

  3. tp5 r3 一个简单的SQL语句调试实例

    tp5 r3 一个简单的SQL语句调试实例先看效果核心代码 public function index() { if (IS_AJAX && session("uid&quo ...

  4. UI:简单的SQL语句

    一.SQL语句如果要在程序运行过程中操作数据库中的数据,那得先学会使用SQL语句1.什么是SQLSQL(structured query language):结构化查询语言SQL是一种对关系型数据库中 ...

  5. 数据库学习之简单的SQL语句

    1.数据库的结构 1.1数据库 不同数据库叫做Catalog(在有的 DBMS 中也称为 Database,即数据库) .採用多 Catalog 以后能够给我们带 来例如以下优点: 便于对各个 Cat ...

  6. 一些简单的SQL语句

    简单的SQL入门 一,简介 1,  一个数据库包含一个或多个表,表包含带有数据的记录(行) 2,  SQL对大小写不敏感,语句的分号看具体情况 二,语法 1,  数据操作语言:DML a)       ...

  7. 简单的SQL语句

    说明:SQL语句大小写都可以,执行一句时,后面可不加分号,如果同时执行两句,就必须加分号,不然会报错. --+空格  是SQL的注释 表格名为users,里面有name和age属性 一.增 inser ...

  8. JDBC之java数据库的连接与简单的sql语句执行

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...

  9. 用jdbc连接数据库并简单执行SQL语句

    一:版本一.这种存在一个问题就是每执行一次操作都会创建一次Connection链接和且释放一次链接 1:创建pojo对象(OR映射,一个pojo类对应一张数据库表)   package com.yin ...

  10. 比Excel还简单的SQL语句查询

    大家好,我是jacky朱元禄,很高兴继续跟大家分享<MySQL数据分析实战>系列课程,前面的课程jacky分享了数据层面增删改查中的增删改,下面的课程我们要说增删改查的这个查,jacky说 ...

随机推荐

  1. 《黄聪:手机移动站SEO优化教程》4、如何实现手机移动网站和PC站点的自主适配

    视频地址:http://www.tudou.com/programs/view/v4Hur5vjav4/ 1.自主适配 A:站点自己做好PC与手机之间的适配,以及手机站各个版式之间的适配.当手机用户通 ...

  2. html元素的显示和隐藏

    div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visibility: hidden;" document.getElementBy ...

  3. C# 通过委托控制进度条以及多线程更新控件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. Form_Form与OAF页面互相调用(案例)

    2014-12-27 Created By BaoXinjian

  5. OAF_EO系列1 - Definition定义(概念)

    2014-06-14 Created By BaoXinjian

  6. sql中实现split()功能

    http://www.cnblogs.com/yangyy753/archive/2011/11/23/2260618.html 数据库中,总是遇到一些字段内容,想根据某个标识截取一下字符串,可是都想 ...

  7. 转载__Activity的启动模式

    http://www.cnblogs.com/plokmju/p/android_ActivityLauncherMode.html 当然,在Android中,除了在AndroidManifest.x ...

  8. JAVA 匿名对象

    /* 匿名对象: 没有名字的对象 匿名对象的使用方式之一: 当对对象方法只调用一次时,我们可以用匿名对象来完成,比较简化. 匿名对象的使用方式之二: 匿名对象可以被当做实参传递 */ class Ca ...

  9. Windows下编译使用Aliyun OSS PHP SDK

    摘要: WIN环境下搭建Aliyun OSS PHP SDK编译运行环境.从PHP的安装逐步完成,SDK的编译运行.即使没有任何PHP基础,也能顺利完成. 安装环境:Win7 64 + PHP 5.6 ...

  10. phpStudy(lnmp)集成环境安装

    phpStudy phpStudy » PHP教程 » phpStudy for Linux (lnmp+lamp一键安装包) phpStudy for Linux (lnmp+lamp一键安装包) ...