我遇到了我的查询问题。其实我也有这种设置数据库: DB SETUP 我用它来从反馈仪插入我的数据。提供的数据就是这样的例子: R; Identifier P34567; Research Number 05/05/2015; Research Date 10:32:39; Research Time 02; Question Number (2-5) 04; User evaluation (1-5). 333 Colaborator ID
在ireport中使用的SQL查询报告用户反馈
我需要建立一个报告为每个colaborator和一个总体报告显示一个部门的所有colaborators。这部分内容尚未实现,所以我正在考虑来自单个部门的所有数据。
我建的是,在我的分贝数行工作的查询,但是当它在一个完整的DB它stucks执行。
,以检索每个colaborator数据我使用的是:
select p.pergunta as Pergunta,
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador=
$P{colaborador} and resposta=1) as '1 - Excelente',
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador=
$P{colaborador} and resposta=2) as '2 - Muito Bom',
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador=
$P{colaborador} and resposta=3) as '3 - Bom',
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador=
$P{colaborador} and resposta=4) as '4 - Regular',
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador=
$P{colaborador} and resposta=5) as '5 - Ruim',
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador=
$P{colaborador} and (resposta=1 or resposta=2 or resposta=3 or resposta=4
or resposta=5)) as 'TOTAL'
from pesquisa as p where colaborador=$P{colaborador} and data between
$P{data_inicial} and $P{data_final}
group by pergunta;
有了这个代码,我可以创建此报告:Colaborator Report
对于我使用此查询总报告:
select p.colaborador, p.pergunta as Pergunta,
(select count(*) from pesquisa where pergunta=p.pergunta and resposta=1)
as '1 - Excelente',
(select count(*) from pesquisa where pergunta=p.pergunta and resposta=2)
as '2 - Muito Bom',
(select count(*) from pesquisa where pergunta=p.pergunta and resposta=3)
as '3 - Bom',
(select count(*) from pesquisa where pergunta=p.pergunta and resposta=4)
as '4 - Regular',
(select count(*) from pesquisa where pergunta=p.pergunta and resposta=5)
as '5 - Ruim',
(select count(*) from pesquisa where pergunta=p.pergunta and colaborador
= p.colaborador and (resposta=1 or resposta=2 or resposta=3 or
resposta=4 or resposta=5)) as 'TOTAL'
from pesquisa as p
group by colaborador, pergunta;
生成报告,结果如下:无法发布更多图片
正如我说的几行它完美的作品,但与大数据它stucks,我不知道如何得到这个结果与另一个查询。我使用所有这些选择的原因是通过行计算每个问题的答案。
你们能不能给我一个灯?
我试图对数据和colaborator字段添加索引,优化它,但一切都没有改变,所以我想我的查询是错误=/ – Yoostah
我得到了我的答案,使用索引尝试后也几乎没有表现的变化,我改变我的计数(*)来计算(resposta)。 – Yoostah