博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【350天】我爱刷题系列109(2018.01.21)
阅读量:7237 次
发布时间:2019-06-29

本文共 1153 字,大约阅读时间需要 3 分钟。

叨叨两句

  1. ~

SQL习题004

下题环境:【Oracle-HR用户】

1

选择雇用时间在1998-02-01到1998-05-01之间的员工姓名,job_id和雇用时间

select first_name,last_name,job_id,hire_datefrom employeeswhere hire_date between to_date('1998-02-01','yyyy-mm-dd') and to_date('1998-05-01','yyyy-mm-dd');

2

选择在1994年雇用的员工的姓名和雇用时间

法1

select last_name,hire_date from hr.employees where hire_date between to_date('1994-1-1','yyyy-mm-dd') and to_date('1994-12-31','yyyy-mm-dd');

法2

select first_name,last_name,hire_datefrom employeeswhere to_char(hire_date,'yyyy-mm-dd')like'1994%' ;select first_name,last_name,hire_datefrom employeeswhere to_char(hire_date,'yyyymmdd')like'1994%';

法3

select first_name,last_name,hire_datefrom employeeswhere hire_date like '%94';Like 只能用于字符串序列, 因此你的 hire_date like 条件Oracle会隐式把 hire_date 进行 to_char 转换, 并且使用系统默认的日期格式, 因此你需要知道系统默认的日期格式才能有效的使用 like 筛选.通常我们都不依赖于系统默认的日期格式(他通常是 DD-MON-RR )而是直接显示指定日期格式, 比如: to_char(hire_date,'yyyy-mm-dd'), 系统默认的格式可能依不同语言的系统而有所不同.

3

显示系统时间

select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual;

4

查询员工的姓名,以及在公司工作的月份数(worked_month),并按月份数降序排列

select first_name,last_name,months_between(sysdate,hire_date) worked_monthfrom employeesorder by worked_month desc;

转载地址:http://sxgfm.baihongyu.com/

你可能感兴趣的文章
idhttp.post方式 调用datasnap rest 远程方法
查看>>
Gulp快速入门
查看>>
TClientDataSet的 fastscript封装
查看>>
有用的国外开源项目网址
查看>>
DataGridView 绑定DataTable方式编辑保存的bug?
查看>>
ComboBox 使用数据绑定时 Sorted 属性的bug
查看>>
BZOJ 3172 单词(ac自动机)
查看>>
具体数学第二版第四章习题(2)
查看>>
DotNetBar.7.0 Crack
查看>>
D3D中深度测试和Alpha混合的关系
查看>>
延时执行和取消延时执行
查看>>
关于线程安全
查看>>
使用Java自带的VisualVM监控远程主机JVM内存使用情况
查看>>
123——Appium Girls活动
查看>>
Linux系统CPU频率调整工具使用
查看>>
使用大于16TB的ext4文件系统
查看>>
jquery ajax cache的问题
查看>>
VIM 与 系统剪切版
查看>>
我用iPad / iTouch来做什么
查看>>
php的mysql_insert_id()返回值问题
查看>>