0

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

结构如下:

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

我的疑问是如何在租赁和租赁(列)中拥有 MTD 和 YTD(子列)的结构。任何关于如何合并相同的想法将不胜感激。

提前致谢,

共同预言家

4

2 回答 2

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。

于 2012-05-18T09:08:20.717 回答
0

从数据库的角度来看,“子列”就像普通列一样被选中,这取决于您用于实际格式化报告的工具如何创​​建您所描述的布局。

于 2012-05-18T05:58:00.727 回答