我的Jasperreport中的SQL查询出了问题。 查询是这样的:
select distinct
t.costcenter,
t.workplace,
t.sap_master_key,
t.product_family,
mb.max_module_name
from
timings t,
max_bbz_per_timing mb
where (
($P{Kostenstelle} is not null and
$P{APS} is not null
and t.timing_id in (
select
timing_id
from
timings
where costcenter = $P{Kostenstelle}
and workplace = $P{APS}
)
)
or
($P{Kostenstelle} is not null
and $P{APS} is null
and t.timing_id in (
select
timing_id
from
timings
where costcenter = $P{Kostenstelle}
)
)
or
($P{Kostenstelle} is null
and $P{APS} is not null
and t.timing_id in (
select
timing_id
from
timings
where workplace = $P{APS}
)
)
)
and mb.timing_id =t.timing_id
and mb.max_module_name is not null
$P{Kostenstelle}
和$P{APS}
是参数。它们都不能为空或只有其中之一。当我在我的开发环境中尝试这个SQL查询时,它会做它应该做的事情,但在JasperSoft Studio中它只在$P{Kostenstelle} is not null and $P{APS} is null
时执行,否则它显示没有结果,尽管它应该。
我希望你们中的某些人可以在这里帮助我,我一无所知。
答案 0 :(得分:1)
这个庞大的SQL脚本就等同于:
HumanPlayer humanPlayer = new HumanPlayer(name); // Renamed
AiPlayer aiPlayer = new AiPlayer("Computer", 0);
player.add(humanPlayer);
player.add(aiPlayer);
如果select distinct
t.costcenter,
t.workplace,
t.sap_master_key,
t.product_family,
mb.max_module_name
from timings t
inner join max_bbz_per_timing mb
on mb.timing_id = t.timing_id and mb.max_module_name is not null
inner join timings t_t
on t_t.timing_id = t.timing_id
and ($P{Kostenstelle} is not null or $P{APS} is not null)
and ($P{Kostenstelle} is null or t_t.costcenter = $P{Kostenstelle})
and ($P{APS} is null or t_t.workplace = $P{APS})
是唯一的,则查询可以更直接:
timing_id