gpt4 book ai didi

mysql - 在 ireport 中使用 SQL 查询来报告用户反馈

转载 作者:行者123 更新时间:2023-11-29 18:45:30 25 4
gpt4 key购买 nike

我的查询遇到问题。我实际上有一个具有以下设置的数据库: 奥 git _a我用它从反馈机器插入我的数据。提供的数据就像这个例子:
R;标识符
P34567;研究编号
2015 年 5 月 5 日;研究日期
10:32:39;研究时间
02;问题编号(2-5)
04;用户评价(1-5)。
第333章 合作者ID

我需要为每个合作者构建一份报告,以及一份显示某个部门的所有合作者的综合报告。该扇区的内容尚未实现,因此我正在考虑来自单个扇区的所有数据。

我构建了一个可以在数据库中使用几行的查询,但是当它在完整的数据库中执行时,它会卡住。

要检索我正在使用的每个协作者的数据:

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;

使用此代码我可以创建此报告:DB SETUP

对于一般报告,我使用此查询:

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;

报告已生成,结果如下:无法发布更多图像

正如我所说,用几行代码它就可以完美地工作,但是当数据量很大时它就会卡住,而且我不知道如何通过另一个查询获得这个结果。我使用所有这些选择的原因是通过行计算每个问题的答案。

你们能给我一盏灯吗?

最佳答案

我的 friend 向我展示了另一种实现此结果的方法。基本上它再次子选择数据结束过滤器以显示它。

SELECT colaborador, 
pergunta,
SUM(EXCELENTE) AS '1 - EXCELENTE',
SUM(MUITOBOM) AS '2 - MUITO BOM',
SUM(BOM) AS '3 - BOM',
SUM(REGULAR) AS '4 - REGULAR',
SUM(RUIM) AS '5 - RUIM'
FROM (
SELECT colaborador,
pergunta,
CASE WHEN resposta = 1 THEN 1 ELSE 0 END AS 'EXCELENTE',
CASE WHEN resposta = 2 THEN 1 ELSE 0 END AS 'MUITOBOM',
CASE WHEN resposta = 3 THEN 1 ELSE 0 END AS 'BOM',
CASE WHEN resposta = 4 THEN 1 ELSE 0 END AS 'REGULAR',
CASE WHEN resposta = 5 THEN 1 ELSE 0 END AS 'RUIM'
FROM pesquisa
WHERE data between str_to_date($P{data_inicial}, "%d/%m/%Y") and str_to_date($P{data_final}, "%d/%m/%Y")
and colaborador = $P{colaborador}
) AS A
GROUP BY colaborador, pergunta

它更好更快。

关于mysql - 在 ireport 中使用 SQL 查询来报告用户反馈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44683504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com