Oracle中with关键字的使用
open p_cr1 for
with sqla as
(select d.*,
(select c.STATICMONTH
from ly_zg_jzfbtstatic c
where c.ID = d.STATIC_ID) as STATICMONTH
from tablename1 d
where d.STATIC_ID in
(select r.ID
from ly_zg_jzfbtstatic r
where to_char(r.STATICMONTH, 'yyyy') = varYear)
and d.DISTNAME = '合计'),
sqlb as
(select d.*,
(select c.STATICMONTH
from ly_zg_lzzfbtstatic c
where c.ID = d.STATIC_ID) as STATICMONTH
from tablename2 d
where d.STATIC_ID in
(select r.ID
from ly_zg_lzzfbtstatic r
where to_char(r.STATICMONTH, 'yyyy') = varYear)
and d.DISTNAME = '合计'),
sqlc as
(select d.*,
(select c.STATICMONTH
from ly_zg_lzfbtstatic c
where c.ID = d.STATIC_ID) as STATICMONTH
from tablename3 d
where d.STATIC_ID in
(select r.ID
from ly_zg_lzfbtstatic r
where to_char(r.STATICMONTH, 'yyyy') = varYear)
and d.DISTNAME = '合计'),
sqld as
(select a.STATICMONTH,
(a.newscount + b.newscount + c.newscount) newscount,
(a.SYCOUNT + b.SYCOUNT + c.SYCOUNT) SYCOUNT,
(a.NEWGCOUNT + b.NEWGCOUNT + c.NEWGCOUNT) NEWGCOUNT,
(a.GYCOUNT + b.GYCOUNT + c.GYCOUNT) GYCOUNT,
(a.MSCCOUNT + b.MSCCOUNT + c.MSCCOUNT) MSCCOUNT,
(a.MGZFCOUNT + b.MGZFCOUNT + c.MGZFCOUNT) MGZFCOUNT,
(c.MSCCOUNT + c.MGZFCOUNT) lzfMSCCOUNT,
(b.MSCCOUNT + b.MGZFCOUNT) lzzfMSCCOUNT,
(a.MSCCOUNT + a.MGZFCOUNT) jzfMSCCOUNT,
(a.newscount + b.newscount + c.newscount + a.NEWGCOUNT +
b.NEWGCOUNT + c.NEWGCOUNT) sum1,
(a.MSCCOUNT + b.MSCCOUNT + c.MSCCOUNT + a.MGZFCOUNT +
b.MGZFCOUNT + c.MGZFCOUNT) sum2 from sqla a, sqlb b, sqlc c
where a.STATICMONTH = b.STATICMONTH
and c.STATICMONTH = a.STATICMONTH)
--
select (select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/01/01') as JAN,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/02/01') as FEB,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/03/01') as MAR,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/04/01') as APRIL,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/05/01') as MAY,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/06/01') as JUNE,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/07/01') as JULY,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/08/01') as AUJUST,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/09/01') as SEPT,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/10/01') as OCT,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/11/01') as NOV,
(select newscount
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/12/01') as DECE
from dual
union all
--
select null as JAN,
null as FEB,
null as MAR,
null as APRIL,
null as MAY,
null as JUNE,
null as JULY,
null as AUGUST,
null as SEPT,
null as OCT,
null as NOV,
null as DECE
from dual
union all
--
select (select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/01/01') as JAN,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/02/01') as FEB,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/03/01') as MAR,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/04/01') as APRIL,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/05/01') as MAY,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/06/01') as JUNE,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/07/01') as JULY,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/08/01') as AUJUST,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/09/01') as SEPT,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/10/01') as OCT,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/11/01') as NOV,
(select SYCOUNT
from sqld
where to_char(STATICMONTH, 'yyyy/mm/dd') = varYear || '/12/01') as DECE
from dual;
当现有的表不满足我们写如意sql,或者是根据现有的表写出如意sql太过复杂,所以Oracle为我们提出了with关键字,帮我们提供了很大的帮助
住,with后面的虚拟表必须用圆括号包起来,并且括号后面必须紧连接select关键字
并且用union all 连接的行中,每行中的列数据类型必须一致,注:null兼容任意数据类型
ye。。。。。。
Oracle中with关键字的使用的更多相关文章
- 如何查询oracle中的关键字
如何查询oracle中的关键字,执行: select * from v$reserved_words
- 【oracle】Oracle中as关键字
在Oracle中as关键字不能用于指定表的别名 在Oracle中指定表的别名时只需在原有表名和表的别名之间用空格分隔即可 但as关键字可以用于指定列的别名 但在存储过程中如果列的别名与原有列名相同,在 ...
- Oracle中的关键字
NVL和COALESCE的区别: nvl(COMMISSION_PCT,0)如果第一个参数为null,则返回第二个参数如果第一个参数为非null,则返回第一个参数 COALESCE(EXPR1,EXP ...
- ORACLE中ESCAPE关键字用法
ESCAPE用法 1.使用 ESCAPE 关键字定义转义符: 在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符. 2.ESCAPE 'escape_character' 允许在字符串中搜 ...
- Oracle中查询关键字select--from--where--group by--having--order by执行顺序
select--from--where--group by--having--order by 这6个查询关键字的执行顺序: 1.from组装来自不同数据源的数据:2.where基于指定的条件对记录行 ...
- oracle中更新关键字merge和 with as关键字
merge是oracle特有的语句,两表关联操作(增.删.改)就效率非常高 merge into table_name alias1 using (table|view|sub_query) alia ...
- Oracle中函数关键字简介
常用的语法:select--from--where--group by--having--order by 1.分组子句group by +con 按什么分组 2.having子句 对上面分组的数据 ...
- Oracle中如何实现Mysql的两表关联update操作
在看<MySQL 5.1参考手册>的时候,发现MySQL提供了一种两表关联update操作.原文如下: UPDATE items,month SET items.price=month.p ...
- 【Oracle】oracle中rownum的说明及使用技巧
oracle中常用到ROWNUM,所以做一些本人对rownum的一些认识和使用技巧的记录,以便备查. 一.rownum的说明 rownum是oracle特有的一个关键字. (1)对于基表,在inser ...
随机推荐
- phpstorm主题设置
毫无疑问,phpstorm很好用,但是安装完成后自带的主题,丑的一匹,所以总结下如何更换主题............. 1.主题下载位置 http://www.phpstorm-themes.com ...
- 从Linux服务器下载文件到本地
通过安装xshell,连接服务器,通过以下命令可以方便的将服务器的文件下载到本地 #下载一个文件 sz filename #下载多个文件 sz filename1 filename2 #下载dir目录 ...
- could not find an installed version of gradle either in android studio
问题描述: 很多人在Ionic升级到3之后,无缘无故发现,当我们添加android平台后,build或者run的时候,命令行窗口给我们提示: 如果在Ionic2时add的android platfor ...
- 2、按钮:Buttons
/* --- page1.html ---*/ <ion-content padding class="page1"> <h1>基本用法,实体框</h ...
- 如何给swing加上alt+x和ctrl+x快捷键
1.给菜单栏上的菜单alt+x快捷键非常简单: private JMenu helpInfo = new JMenu("帮助"); helpInfo.setMnemonic(Key ...
- 二、MVC3+EF单表增删改查
document 表为例 写入静态类 NorthwindDataProvider: Controller可直接调用:如 //获取document表全部数据 NorthwindDataProvider. ...
- Linux虚拟系统安装——Ubuntu18.04 & CentOS6.5
Linux虚拟系统安装--Ubuntu18.04 & CentOS6.5 摘要:Linux简介.虚拟系统安装.系统备份与文件介绍 1. Linux简介 (1)1968年,MIT.Bell实验室 ...
- Flowchart
1. 工具可使用 https://www.processon.com 2.
- SharePoint 2013 - System Features
1. Embed Information & Convert to PDF 功能,在文档的preview界面(hover panel); 2. Share功能可以选择是否发送邮件 -- Don ...
- qt 创建线程
http://www.cnblogs.com/xinxue/p/6840315.html Qt 之 QtConcurrent 本文以 Qt 中的 QtConcurrent::run() 函数为例,介绍 ...