Mysql 需要ireport交叉表中两个单独类别行的报告吗
这是我将要使用的查询Mysql 需要ireport交叉表中两个单独类别行的报告吗,mysql,jasper-reports,ireport,Mysql,Jasper Reports,Ireport,这是我将要使用的查询 select monthNmae, monthID, achievement , target from salse 上面的查询返回以下结果 month | monthID | achievement | target jan 1 12 10 feb 2 56 20 mar 3 9 20 . .
select monthNmae, monthID, achievement , target from salse
上面的查询返回以下结果
month | monthID | achievement | target
jan 1 12 10
feb 2 56 20
mar 3 9 20
. . . .
. . . .
. . . .
. . . .
dec 12 70 68
我想要一张Jasper report的表格
month jan feb mar ............... Dec
Achievement 12 56 9 .............. 70
target 10 26 20 .............. 68
有什么帮助吗?您可以编写一个查询,以获得所需格式的数据。在MySQL中,您可以使用聚合函数和
CASE
语句:
select src_col as month,
sum(case when month = 'jan' then value end) `jan`,
sum(case when month = 'feb' then value end) `feb`,
sum(case when month = 'mar' then value end) `mar`, -- add other months here
sum(case when month = 'dec' then value end) `dec`
from
(
select month, monthid, achievement value, 'achievement' src_col
from salse
union all
select month, monthid, target value, 'target' src_col
from salse
) src
group by src_col
看