【考试】简单的sql语句
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语句的更多相关文章
- [20190328]简单探究sql语句相关mutexes.txt
[20190328]简单探究sql语句相关mutexes.txt --//摘要:http://www.askmaclean.com/archives/understanding-oracle-mute ...
- 四种简单的sql语句(增删改查语句)
四种简单的sql语句(增删改查语句) 一.插入语句 insert into [table] ([column],[column],[column]) values(?,?,?) 二.删除语句 dele ...
- tp5 r3 一个简单的SQL语句调试实例
tp5 r3 一个简单的SQL语句调试实例先看效果核心代码 public function index() { if (IS_AJAX && session("uid&quo ...
- UI:简单的SQL语句
一.SQL语句如果要在程序运行过程中操作数据库中的数据,那得先学会使用SQL语句1.什么是SQLSQL(structured query language):结构化查询语言SQL是一种对关系型数据库中 ...
- 数据库学习之简单的SQL语句
1.数据库的结构 1.1数据库 不同数据库叫做Catalog(在有的 DBMS 中也称为 Database,即数据库) .採用多 Catalog 以后能够给我们带 来例如以下优点: 便于对各个 Cat ...
- 一些简单的SQL语句
简单的SQL入门 一,简介 1, 一个数据库包含一个或多个表,表包含带有数据的记录(行) 2, SQL对大小写不敏感,语句的分号看具体情况 二,语法 1, 数据操作语言:DML a) ...
- 简单的SQL语句
说明:SQL语句大小写都可以,执行一句时,后面可不加分号,如果同时执行两句,就必须加分号,不然会报错. --+空格 是SQL的注释 表格名为users,里面有name和age属性 一.增 inser ...
- JDBC之java数据库的连接与简单的sql语句执行
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...
- 用jdbc连接数据库并简单执行SQL语句
一:版本一.这种存在一个问题就是每执行一次操作都会创建一次Connection链接和且释放一次链接 1:创建pojo对象(OR映射,一个pojo类对应一张数据库表) package com.yin ...
- 比Excel还简单的SQL语句查询
大家好,我是jacky朱元禄,很高兴继续跟大家分享<MySQL数据分析实战>系列课程,前面的课程jacky分享了数据层面增删改查中的增删改,下面的课程我们要说增删改查的这个查,jacky说 ...
随机推荐
- bzoj2152 聪聪可可
Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...
- 《黄聪:手机移动站SEO优化教程》3、如何禁止百度对PC网站进行自动转码
视频地址:http://v.youku.com/v_show/id_XNzE2OTM0NzU2.html
- eclipse常用插件安装
打开资源文件所在目录 EasyExplorer 下载:http://sourceforge.net/projects/easystruts/ 直接拷贝到%ECLIPSE_HOME%\plugins 或 ...
- openmp并行计算
#include <omp.h>#include <stdio.h>#include <stdlib.h> void test(int n){ for (int i ...
- linux下安装easy_install的方法
python中的easy_install工具,类似于Php中的pear,或者Ruby中的gem,或者Perl中的cpan,那是相当的爽歪歪了如果想使用 如果想使用easy_install工具,可能需要 ...
- Mac下lombok无法安装到eclipse mars
eclipse升级到mars之后 , 在mac下已经不再是文件夹中有很多文件的eclipse了 , 只有一个单独的app文件.用原来的方式运行lombok再选eclipse.app已经不行了. 自己鼓 ...
- unset是不能清除保存在本地电脑上的cookie的,用于session就可以(弄了半天原来是这样)
unset($_COOKIE["historyWord[$wordId]"]); 这样是不行的,unset只是将变量在脚本运行时注销,但是cookie是写在客户端的,下一次还是可以 ...
- IDEA激活服務器
IDEA: http://www.iteblog.com/idea/key.php webstorm11:http://15.idea.lanyus.com/
- linux 可用内存查看
用free命令查看. 下面是一个例子(单位是MB): [root@linuxzgf ~]# free -m total used free shared buffers cachedMem: 7982 ...
- jQuery formValidator表单验证插件常见问题
1. 如何实现一个控件,根据不同的情况,实现不同的控制? 2. 一个页面上我有几个tab页,如何实现每个Tab页上的控件单独校验? 3. 我采用的页面上文字问题的方式,点提交的时候, ...