Birt过滤器数据集

时间:2015-05-14 08:41:48

标签: sql-server birt

我目前有一个像这样的SQL代码

select id1, ' ' as id2, balance1, 0 as balance2   
from table 1  
union  
select ' ' as id1, id2, 0 as balance1, balance2   
from table 2  

表1和表2没有关系,所以我不能使用join。

在我的报告模板中,我创建了一个表格,该表格与数据集绑定,并带有sql代码输出的列。

我在表格中放了两个细节行 目前喜欢这个

head:         ID                       BALANCE    
detail1:     [id1]                 [balance1]   
detail2:     [id2]                            [balance2]      

我需要在detail1中过滤掉table2中的数据,并在detail2中过滤掉table1中的数据。我该怎么做呢?

目前我的表格报告结果也是这样的交叉数据:

[id1]     [balance1]   
[id2]               [balance2]  
[id1]     [balance1]   
[id2]               [balance2]  

我需要它在顶部和底部之间的一个细节reuslt像这样:

[id1]     [balance1]   
[id1]     [balance1]     
[id2]               [balance2]    
[id2]               [balance2]  

我该如何设置报告模板?

1 个答案:

答案 0 :(得分:0)

我认为您需要这样的查询:

SELECT *
FROM (
    SELECT id1, ' ' as id2, balance1, 0 as balance2, 1 As ord   
    FROM table 1  
    UNION ALL  
    SELECT ' ' as id1, id2, 0 as balance1, balance2, 2 As ord
    FROM table 2  ) DT
ORDER BY 
    ord, id1, id2