Table
Date aa1
2005-1-1 100
2005-1-2 99
...如何Group by得到这样的结果 季度 aa1_Sum
2005-1 2031
2005-2 1962
Date aa1
2005-1-1 100
2005-1-2 99
...如何Group by得到这样的结果 季度 aa1_Sum
2005-1 2031
2005-2 1962
解决方案 »
- materialized view log 中的cache|nocache是啥意思
- 谁能教我一个辨认Oracle数据库的位置方法
- oracle触发器如何得到被更新的数据
- (在线坐等)ibatis里面怎样将下面SQL语句写成XML文件
- 如何实现分段存储
- 如何以最少的时间读取出大量数据
- 求救:oracle中如何翻译“ StickyDate > DateAdd( y, 20, GetDate() )”这句?
- 救命!!SqlServer的Image类型与Oracle的Blob互相写入的问题
- job不能自动执行的问题
- 菜鸟问题:Solaris+Oracle+Apache+JavaBean
- ASP中连接Oracle数据库的问题。急~~~~~~~~~~~
- C语言 如何将变量 插入mySQL数据库,mySQL C语言封装变量的问题
group by to_char(date,'yyyy-mm')
select substr(to_char(date,'yyyy-mm'),1,5)||
(case when substr(to_char(date,'yyyy-mm'),6,7) between '01' and '03' then '01'
when substr(to_char(date,'yyyy-mm'),6,7) between '04' and '06' then '02'
when substr(to_char(date,'yyyy-mm'),6,7) between '07' and '09' then '03'
else '04' end ) as 季度,
sum(aa1)
from dual
group by
select substr(to_char(date,'yyyy-mm'),1,5)||
(case when substr(to_char(date,'yyyy-mm'),6,7) between '01' and '03' then '01'
when substr(to_char(date,'yyyy-mm'),6,7) between '04' and '06' then '02'
when substr(to_char(date,'yyyy-mm'),6,7) between '07' and '09' then '03'
else '04' end )
SQL> SELECT to_char(DATE '2005-5-1','yyyy-q') FROM dual;TO_CHAR(DATE'2005-5-1','YYYY-Q
------------------------------
2005-2最简单方法就是这样:select to_char(date,'yyyy-Q') as 季度 ,sum(aa1) as aa1_Sum from Table
group by to_char(date,'yyyy-Q')