我使用的查询(在链接右侧)生成了此结果(左侧) 请参阅http://www.sqlfiddle.com/#!2/f34f1/1
我是 JasperReports 和 MySql 的新手。 我想
我能够计算在5天内被推荐的客户
SELECT COUNT(*) from
(select p.patient_id,
(CASE WHEN st.smear_result <> 'NEGATIVE' OR st.gxp_result='MTB+'
THEN IF(DATEDIFF(r.date_referred,MIN(st.date_smear_tested)) IS NULL,'N/A',(DATEDIFF(r.date_referred,MIN(st.date_smear_tested))))
ELSE
(CASE WHEN st.smear_result='NEGATIVE' OR st.gxp_result='MTB-'
THEN IF(DATEDIFF(r.date_referred,MAX(st.date_smear_tested)) IS NULL,'N/A',(DATEDIFF(r.date_referred,MAX(st.date_smear_tested))))
ELSE 'N/A' end )END) as days_taken,
IF(r.date_referred IS NULL,'N/A',r.date_referred) date_referred
from patient as p
right outer join sputum_test as st on p.patient_id=st.patient_id
right outer join referral as r on r.patient_id=st.patient_id
where p.suspected_by is not null and (p.patient_status='SUSPECT' or p.patient_status='CONFIRMED')
group by p.patient_id
having days_taken <=5) AS SUBQUERY;
超过5天被推荐的客户数量。
SELECT COUNT(*) from
(select p.patient_id,
(CASE WHEN st.smear_result <> 'NEGATIVE' OR st.gxp_result='MTB+'
THEN IF(DATEDIFF(r.date_referred,MIN(st.date_smear_tested)) IS NULL,'N/A',(DATEDIFF(r.date_referred,MIN(st.date_smear_tested))))
ELSE
(CASE WHEN st.smear_result='NEGATIVE' OR st.gxp_result='MTB-'
THEN IF(DATEDIFF(r.date_referred,MAX(st.date_smear_tested)) IS NULL,'N/A',(DATEDIFF(r.date_referred,MAX(st.date_smear_tested))))
ELSE 'N/A' end )END) as days_taken,
IF(r.date_referred IS NULL,'N/A',r.date_referred) date_referred
from patient as p
right outer join sputum_test as st on p.patient_id=st.patient_id
right outer join referral as r on r.patient_id=st.patient_id
where p.suspected_by is not null and (p.patient_status='SUSPECT' or p.patient_status='CONFIRMED')
group by p.patient_id
having days_taken > 5) AS SUBQUERY;
但我如何获得计数尚未提交嫌疑人/已确认的客户?
我的计划是以某种方式将结果作为2列:
第1列:显示3个条件,第2列:显示它们旁边的行总和。
我将在 iReport 设计器中传递解决方案查询,将3个条件的饼图作为标签,并显示每个切片的百分比。
答案 0 :(得分:0)
这样的事情应该有效:
SELECT SUM(days_taken <= 5) AS within_5_days,
SUM(days_taken > 5) AS more_than_5,
SUM(days_taken IS NULL) as not_yet_referred
FROM (...) AS subquery
显然,子查询应为未引用的客户端生成NULL
,而不是原始子查询中的N/A
。