使用Oracle SQL的多维数据结果

时间:2014-08-20 22:09:42

标签: sql oracle multidimensional-array olap

我想知道我是否可以编写一个可以生成多维结果集的SQL查询,如下所示。

enter image description here

我确信这可以使用OLAP完成,但我对OLAP没有实际知识。

我的查询编写如下:

select sfrstcr_term_code term, 
stvrsts_desc reg_status,
count(distinct SFRSTCR_PIDM) count
from sfrstcr,stvrsts 
where sfrstcr_term_code = 201401 
and SFRSTCR_ADD_DATE > to_date('21/02/2014','DD/MM/YYYY')
and SFRSTCR_RSTS_CODE is not null
and sfrstcr_camp_code = 'L'
and stvrsts_code = SFRSTCR_RSTS_CODE
group by sfrstcr_term_code, stvrsts_desc

union

select sfrstcr_term_code term, 
stvrsts_desc reg_status,
count(distinct SFRSTCR_PIDM) count
from sfrstcr,stvrsts 
where sfrstcr_term_code = 201301 
and SFRSTCR_ADD_DATE > to_date('22/02/2013','DD/MM/YYYY')
and SFRSTCR_RSTS_CODE is not null
and sfrstcr_camp_code = 'L'
and stvrsts_code = SFRSTCR_RSTS_CODE
group by sfrstcr_term_code, stvrsts_desc

union

select sfrstcr_term_code term, 
stvrsts_desc reg_status,
count(distinct SFRSTCR_PIDM) count
from sfrstcr,stvrsts 
where sfrstcr_term_code = 201201 
and SFRSTCR_ADD_DATE > to_date('24/02/2012','DD/MM/YYYY')
and SFRSTCR_RSTS_CODE is not null
and sfrstcr_camp_code = 'L'
and stvrsts_code = SFRSTCR_RSTS_CODE
group by sfrstcr_term_code, stvrsts_desc

order by 2,1

上述查询的结果如下:

enter image description here

由于

0 个答案:

没有答案