生合并列
birt merge columns
我用它来生成用户报告。我需要创建一个显示充值的数量和总和以及提款的总和和数量。
我创建了两个数据集:
select WAL_TRANSACTION.PARTY_ID, sum(WAL_TRANSACTION.AMOUNT) amountdep, count(WAL_TRANSACTION.AMOUNT) countdep
from WAL_TRANSACTION
where WAL_TRANSACTION.TRANSACTION_TYPE=1
and WAL_TRANSACTION.STATUS='completed'
group by WAL_TRANSACTION.PARTY_ID
和
select WAL_TRANSACTION.PARTY_ID, sum(WAL_TRANSACTION.AMOUNT) amountwi, count(WAL_TRANSACTION.AMOUNT) countwi
from WAL_TRANSACTION
where WAL_TRANSACTION.TRANSACTION_TYPE=2
and WAL_TRANSACTION.STATUS='completed'
group by WAL_TRANSACTION.PARTY_ID
然后创建了一个 BIRT 联合数据集来合并两者(全外连接)
问题是在结果中,您最终得到 2 PARTY_ID 列,有没有办法将它们合并为一列?
sample current result
只需使用条件聚合:
select t.PARTY_ID,
sum(case when t.TRANSACTION_TYPE = 1 then t.AMOUNT end) as amountdep_1,
sum(case when t.TRANSACTION_TYPE = 1 then 1 else 0 end) as countdep_1,
sum(case when t.TRANSACTION_TYPE = 2 then t.AMOUNT end) as amountdep_2,
sum(case when t.TRANSACTION_TYPE = 2 then 1 else 0 end) as countdep_2
from WAL_TRANSACTION t
where t.TRANSACTION_TYPE in (1, 2) and
t.STATUS = 'completed'
group by t.PARTY_ID;
你不需要子查询。
我用它来生成用户报告。我需要创建一个显示充值的数量和总和以及提款的总和和数量。
我创建了两个数据集:
select WAL_TRANSACTION.PARTY_ID, sum(WAL_TRANSACTION.AMOUNT) amountdep, count(WAL_TRANSACTION.AMOUNT) countdep
from WAL_TRANSACTION
where WAL_TRANSACTION.TRANSACTION_TYPE=1
and WAL_TRANSACTION.STATUS='completed'
group by WAL_TRANSACTION.PARTY_ID
和
select WAL_TRANSACTION.PARTY_ID, sum(WAL_TRANSACTION.AMOUNT) amountwi, count(WAL_TRANSACTION.AMOUNT) countwi
from WAL_TRANSACTION
where WAL_TRANSACTION.TRANSACTION_TYPE=2
and WAL_TRANSACTION.STATUS='completed'
group by WAL_TRANSACTION.PARTY_ID
然后创建了一个 BIRT 联合数据集来合并两者(全外连接)
问题是在结果中,您最终得到 2 PARTY_ID 列,有没有办法将它们合并为一列?
sample current result
只需使用条件聚合:
select t.PARTY_ID,
sum(case when t.TRANSACTION_TYPE = 1 then t.AMOUNT end) as amountdep_1,
sum(case when t.TRANSACTION_TYPE = 1 then 1 else 0 end) as countdep_1,
sum(case when t.TRANSACTION_TYPE = 2 then t.AMOUNT end) as amountdep_2,
sum(case when t.TRANSACTION_TYPE = 2 then 1 else 0 end) as countdep_2
from WAL_TRANSACTION t
where t.TRANSACTION_TYPE in (1, 2) and
t.STATUS = 'completed'
group by t.PARTY_ID;
你不需要子查询。