呵,又要语句简短,又要执行效率高,可以考虑使用数据库的一些专有函数(各数据库不一样),再不就处理结果集,先前只执行简单的查询。传说中偶的9000个字符的sql语句照样执行,除了慢,呵呵,后已修改成处理结果集。所以有了如上建议。
解决方案 »
- 可以不可以再select *,后面接nvl((select a from b),0) from 这样
- 如何查找查看类日志表记录
- oracle安装后 sqlplus打开后不是登陆框
- 请教:关于Oracle的高级复制功能
- oracle安装详细步骤及注意事项
- oracle连接数影响应用服务器读取数据
- 新手弱弱地问一下
- 请问Oracle 是不是把它管理的数据空间全部或分为 "表空间"这个东西? 新建用户的时候都要指定表空间
- 数据库面试题,急~~~~~~~~~~~~~~~
- sql语句构造,按条计分 (在线)
- 怎样从oracle数据库中导出某个用户下的所有存储过程,包,函数?
- 存储过程中创建临时表,为何没有权限?
语句复杂点倒没事,主要是效率不行,数据在万以上就很慢了.我用的是oracle 9i
sum(case when to_char(date_col,'dd') = '02' then 1 else 0 end) date_02,
....
sum(case when to_char(date_col,'dd') = '31' then 1 else 0 end) date_31
from ..
group by 类别.
from
(select bj,to_char(thedate,'DD') l_date,count(1) times
from a
where thedate>= to_date('2006/02/01','YYYY/mm/dd')
and thedate< to_date('2006/03/01','YYYY/mm/dd'))
group by rollup (bj,l_date)
having bj is not null and l_date is not null
select bj,l_date,count(1)
from
(select bj,to_char(thedate,'DD') l_date
from a
where thedate>= to_date('2006/02/01','YYYY/mm/dd')
and thedate< to_date('2006/03/01','YYYY/mm/dd')
and bound1=10)
group by rollup (bj,l_date)
having bj is not null and l_date is not null
select bj,to_char(thedate,'DD') l_date
from a
where thedate>= to_date('2006/02/01','YYYY/mm/dd')
and thedate< to_date('2006/03/01','YYYY/mm/dd')
and bound1=10关键是外面这个rollup要好好体会用法
select bj,l_date, count(1)
from table
group by rollup (bj,l_date)后面的having语句
1)bj is not null 是为了把对于l_date的小计过滤掉
2)l_date is not null 是为了把对于bj的小计过滤掉
如果楼主需要小计的话那就把后面的having语句去掉就好了