我有一个专栏Status
,我想知道有多少行是“Pendings
”,有多少是“Finalized
”
我试过了:
Variable class = java.lang.Integer
Calculation = Sum
ResetType = Report
Increment type = None
Variable expression = $F{tbl_suspensao_status}.equals("Finalized") ? 0 : 1
但它不起作用。
查询:
SELECT
tbl_suspensao.`codigoBeneficiario` AS tbl_suspensao_codigoBeneficiario,
tbl_suspensao.`contrato` AS tbl_suspensao_contrato,
tbl_suspensao.`data_fim` AS tbl_suspensao_data_fim,
tbl_suspensao.`data_inicio` AS tbl_suspensao_data_inicio,
tbl_suspensao.`status` AS tbl_suspensao_status,
tbl_usuario.`nome` AS tbl_usuario_nome,
tbl_suspensao.`nomeBeneficiario` AS tbl_suspensao_nomeBeneficiario
FROM
`tbl_usuario` tbl_usuario INNER JOIN `tbl_suspensao` tbl_suspensao ON tbl_usuario.`codigo` = tbl_suspensao.`usuario_id`
WHERE
AND tbl_suspensao.`data_inicio` BETWEEN $P{Data_Inicio} AND $P{Data_Fim}
答案 0 :(得分:1)
select
sum(if(Status = "Pendings", 1, 0)) Pendings,
sum(if(Status = "Finalized", 1, 0)) Finalized
from table
左右
select
sum(Status = "Pendings") Pendings,
sum(Status = "Finalized") Finalized
from t1
答案 1 :(得分:1)
SELECT status, count(*) from table where status='pending' or status='finalized'
group by status
答案 2 :(得分:0)
错误的顺序1和0.将表达式更改为
Variable expression = $F{tbl_suspensao_status}.equals("Finalized") ? 1 : 0
P.S。 SQL中的计算总和是SQL解决方案,但不是iReport-solution