问题描述: 现在我要按起事和结束两个时间来查询年季月度数据.它所查询的表都是在一个表中,但是每条数据都是按月来存储的;
那么当我要查询季度年度数据的话,我怎么查询?
比如我输入08年3月到08年12月,要查询的是季度. 应该是返回的3,6,9,12月份4条数据.
年度就是取每年的12月份数据?
请问各位大侠,怎么能做到呢?谢谢了
那么当我要查询季度年度数据的话,我怎么查询?
比如我输入08年3月到08年12月,要查询的是季度. 应该是返回的3,6,9,12月份4条数据.
年度就是取每年的12月份数据?
请问各位大侠,怎么能做到呢?谢谢了
select product,sum(product_count) from table_test where to_char(date1,'yyyy-mm')='2008-10' group by product;--按季:
select product,sum(product_count) from table_test where to_char(date1,'yyyy-mm')in('2008-07','2008-08','2008-09') group by product;--按年:
select product,sum(product_count) from table_test where to_char(date1,'yyyy')='2007' group by product;
to_char(日期,'yyyy-mm'),
sum(收入),
sum(资出)
from Table_test
where to_char(日期,'yyyy-mm-dd')>='2007-01-01' and
to_char(日期,'yyyy-mm-dd')<='2007-12-31'
group by 名称,to_char(日期,'yyyy-mm');
select 季度,sum(收入) from (select 月,收入,case when 月=1,2,3 then 1
when 月=4,5,6 then 2
when 月=7,8,9 then 3
when 月=10,11,12 then 4
end 季度
from table where 月 > and 月<多少)
group by 季度
From Table_Test
Where 日期 In (Select 日期
From (Select To_Char(日期, 'q') As 季度, Max(日期) As 日期
From Table_Test
Where To_Char(日期, 'yyyy-mm-dd') >= '2007-01-01'
And To_Char(日期, 'yyyy-mm-dd') <= '2007-12-31'
Group By To_Char(日期, 'q')))