很久不用SQL语句了,貌似入职新公司后,又回归到了三年前的SQL时代,一写一坨的SQL好吧,也当回归一下过去的知识。

下面是统计2月份某数据的计费统计

select  t.telno as 主号,VID 副号,t.area_code 地区, t.reg_time 注册时间,t.reg_source 注册工号,t.bill_start_date 计费时间,
(case state when 0
then '0 正常' end)计费状态 from t_unreg_log t where t.bill_start_date<to_date('20150301','yyyymmdd') and t.bill_start_date>to_date('20150201','yyyymmdd')
and t.unreg_time<to_date('20150301','yyyymmdd') and t.unreg_time>to_date('20150201','yyyymmdd')
and t.type='9' union
select t.telno as 主号,VID 副号,t.area_code 地区, t.reg_time 注册时间,t.reg_source 注册工号,t.bill_start_date 计费时间,
(case state when 0
then '0 正常' end)计费状态 from t_unreg_log t where t.bill_start_date<to_date('20150301','yyyymmdd') and t.bill_start_date>to_date('20150201','yyyymmdd')
and t.unreg_time>to_date('20150301','yyyymmdd')
union select t.telno as 主号,VID 副号,t.area_code 地区, t.reg_time 注册时间,t.reg_source 注册工号,t.bill_start_date 计费时间,
(case state when 0
then '0 正常' end)计费状态  from t_unreg_log t where t.bill_start_date is not null
and t.bill_start_date<to_date('20150201','yyyymmdd') and t.unreg_time<to_date('20150301','yyyymmdd') and t.unreg_time>to_date('20150201','yyyymmdd')
and t.type='9'
union
select t.telno as 主号,VID 副号,t.area_code 地区, t.reg_time 注册时间,t.reg_source 注册工号,t.bill_start_date 计费时间,
(case state when 0
then '0 正常' end)计费状态 from t_online_info t where t.bill_start_date is not null and t.bill_start_date<to_date('20150301','yyyymmdd'))

写完之后发现这么多的冗余代码。

ORACLE 语句关联统计的更多相关文章

  1. 53个Oracle语句优化规则详解(转)

    Oracle sql 性能优化调整  1. 选用适合的ORACLE优化器        ORACLE的优化器共有3种:a. RULE (基于规则)   b. COST (基于成本) c. CHOOSE ...

  2. oracle里的统计信息

    1 oracle里的统计信息 Oracle的统计信息是这样的一组数据,存储在数据字典,从多个维度描述了oracle数据库对象的详细信息,有6种类型 表的统计信息:记录数.表块的数量.平均行长度等 索引 ...

  3. 关于Oracle开启自动收集统计信息的SPA测试

    主题:关于Oracle开启自动收集统计信息的SPA测试 环境:Oracle RAC 11.2.0.4(Primary + Standby) 需求:生产Primary库由于历史原因关闭了自动统计信息的收 ...

  4. Oracle 语句中“||”代表什么啊?

    Oracle 语句中“||”代表什么啊? Oracle 语句中“||”代表什么啊?跟ServerSQL中的字符串的连接符“+”是一个概念么? 1. 恩是的 是一个含义...select '1'||'2 ...

  5. 基于Oracle的SQL优化(崔华著)-整理笔记-第5章“Oracle里的统计信息”

    第5章“Oracle里的统计信息” 详细介绍了Oracle数据库里与统计信息相关的各个方面的内容,包括 Oracle数据库中各种统计信息的分类.含义.收集和查看方法,以及如何在Oracle数据库里正确 ...

  6. 学习ThinkPHP的第21天---关联预载入、关联统计

    ThinkPHP关联预载入 预载入的作用是减少执行SQL语句,进而提升程序的性能. public function join(){ //用于监听SQL Db::listen(function ($sq ...

  7. MyBatis项目实战 快速将MySQL转换成Oracle语句

    一.前言 因项目需求,小编要将项目从mysql迁移到oracle中 ~ 之前已经完成 数据迁移 (https://zhengqing.blog.csdn.net/article/details/103 ...

  8. [转载]T-SQL(Oracle)语句查询执行顺序

    原文链接:http://blog.sina.com.cn/s/blog_61c006ea0100mlgq.html sql语法的分析是从右到左,where子句中的条件书写顺序,基本上对sql性能没有影 ...

  9. 性能测试常用Oracle语句

    性能测试常用Oracle语句 显示数据库当前的连接数 select count(*) from v$process; 显示数据库最大连接数: select value from v$parameter ...

随机推荐

  1. jquery ajax请求了两次问题

    页面有一个请求form: <form method="post" id="signin"> <label for="orderid& ...

  2. 关于解决android4.0系统中菜单无法添加Icon的问题

    在Android4.0系统中,创建菜单Menu,然后通过setIcon方法给菜单添加图标是无效的,图标不会显出来,而之前的系统中是可以显示出来的.这个问题的根本原因在于4.0系统中,涉及到菜单的源码类 ...

  3. spark1.2.0安装

    standalone 安装SCALA 下载.解压.加入环境变量 安装spark1.2.0 下载.解压.加入环境变量 tar zxvf spark--bin-.tgz export SPARK_HOME ...

  4. bigDecimal 使用小结

    关于四舍五入: 
ROUND_HALF_UP: 遇到.5的情况时往上近似,例: 1.5 ->;2 
ROUND_HALF_DOWN : 遇到.5的情况时往下近似,例: 1.5 ->;1 注 ...

  5. 【Android Api 翻译4】android api 完整翻译之Contacts Provider (学习安卓必知的api,中英文对照)

    Contacts Provider 电话簿(注:联系人,联络人.通信录)提供者 ------------------------------- QUICKVIEW 快速概览 * Android's r ...

  6. PreparedStatement和Statement的区别

    转自:http://blog.sina.com.cn/s/blog_77eba18f01019csh.html 1. PreparedStatement接口继承Statement, PreparedS ...

  7. java 集合类简单的分析1

          java中的集合类是很常见的,ArrayList,HashSet,HashMap等,现在就让我们来看下他们的各个类之间的关系图.      Collection ├List │├Linke ...

  8. XML DTD验证

    XML DTD验证 一.什么是DTD 文档类型定义(DTD:Document Type Definition)可定义合法的XML文档构建模块.它使用一系列合法的元素来定义文档的结构. DTD 可被成行 ...

  9. Http StatuCode说明

    HTTP 200 - 文件被正常的访问 HTTP 302 - 临时重定向 HTTP 400 - 请求无效 HTTP 401.1 - 未授权:登录失败 HTTP 401.2 - 未授权:服务器配置问题导 ...

  10. 服务器调用JS

    服务器控件调用JS一.两类JS的触发设计1.提交之前的JS -- 加js的事件例:<script language="javascript"> // 构造函数 func ...