如何在矩阵报告中包含列的子列?

时间:2012-05-18 05:48:59

标签: oracle oracle10g

需要在矩阵报告的列中包含子列。

结构如下:

            Lease   |      Rental
          MTD | YTD |     MTD |  YTD
         -----+-----+---------+-----
Segment       |     |         |

我怀疑如何拥有MTD和YTD(子列)的结构 在租赁和租赁(列)。关于如何融入相同的想法 将不胜感激。

提前致谢,

Co-Oracler

2 个答案:

答案 0 :(得分:1)

确切的解决方案将取决于您的数据模型,但是您忽略了向我们提供表格。所以这只是一个可能的解决方案的迹象。相关技术是在查询投影中使用CASE。

select 
       segment
       , sum(case ( when type = 'LEASE' and t_date >= trunc(sysdate, 'MON') then
                t_qty else 0 end) as lease_mtd
       , sum(case ( when type = 'LEASE' then
                t_qty else 0 end) as lease_ytd
       , sum(case ( when type = 'RENTAL'  then
                t_qty else 0 end) as rental_mtd
       , sum(case ( when type = 'RENTAL' and t_date >= trunc(sysdate, 'YYYY') then
                t_qty else 0 end) as rental_ytd
from your_tablee 
where t_date >= trunc(sysdate, 'YYYY')

sysdate上的TRUNC()是一个巧妙的技巧,它产生格式掩码指示的日期。所以'MON'面具产生当月的第一天,'YYYY'产生当年的01-JAN。

答案 1 :(得分:0)

从数据库的角度来看,“子列”的选择与普通列一样,取决于您用于实际格式化报表的工具,如您所描述的那样创建布局。