select to_char(rq,'yyyy-mm-dd') rq,max(sk),max(dm),max(data),min(sk),min(dm),min(data)
from table1 group by to_char(rq,'yyyy-mm-dd')
from table1 group by to_char(rq,'yyyy-mm-dd')
解决方案 »
- 触发器
- 分组求和的问题
- 请教gt-grid与struts2结合,后台分页的问题
- 启动oracledbconsoleorcl 发生服务特定错误: 2
- oracle forms中的并发程序(concurrent program)是什么样的一个概念
- 如何优化数据表
- PLS-00103:Encountered the symbol "LOOP" when expecting one of the following
- m_pConnection->Execute((_bstr_t)sql,&vtMissing,adCmdText);报运行错误,如何解决
- 请教一个SQL语句问题
- OracleOraHome90TNSListener服务与Tomcat服务好象存在冲突??
- 创建触发器
- 小弟,这周终于开始学oracle了,为什么我在 SQL plus 里边创建数据库和创建表空间,提示说没有权限.
SQL> select * from b;B1 B2 B3 B4
---------- ---------- ---------- -----------
1 3 24-AUG-05 2005-8-24 1
2 4 24-AUG-05 2005-8-24 1
3 4 24-AUG-05 2005-8-24 1
5 6 23-AUG-05 2005-8-23 1Executed in 0.016 seconds
SQL> select max(b1),max(b2),min(b2),max(b3),max(b4) from b group by trunc(b4,'dd');MAX(B1) MAX(B2) MIN(B2) MAX(B3) MAX(B4)
---------- ---------- ---------- ---------- -----------
5 6 6 23-AUG-05 2005-8-23 1
3 4 3 24-AUG-05 2005-8-24 1Executed in 0.016 seconds
我觉得用分析函数最简单了,如果你的oracle是817以上版本的
select distinct trunc(rq),--如果rq是date类型,如果是类似yyyy-mm-dd的字串类型直接用rq
max(data) over(partition by trunc(rq)),
min(data) over(partition by trunc(rq)),
first_value(sk) over(partition by trunc(rq) order by data desc),--最大值出现的时刻
first_value(sk) over(partition by trunc(rq) order by data)--最小值出现的时刻
from table1
from
(select to_char(rq,'yyyy-mm-dd') rq,max(data) maxdata,min(data) mindata
from table1 group by to_char(rq,'yyyy-mm-dd')) a,
table1 b,table1 c
where to_char(b.rq,'yyyy-mm-dd')=a.rq and b.data=a.maxdata
and to_char(c.rq,'yyyy-mm-dd')=a.rq and c.data=a.mindata
group by a.rq,a.maxdata,a.mindata