gpt4 book ai didi

mysql - 我的关节乘以我的总和结果

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

我尝试执行此查询,但结果乘以 4 倍该字段是 Time 类型,也许这就是问题所在?无论如何,当我连接其他表时,会出现错误的结果,每个连接都会使结果增加一倍。

我操作表格来匹配结果,我期望总和为 40000,但是当我运行显示 160000 的查询时;

这是我的查询:

SELECT SUM(tempoexposicao) AS exposicao 
FROM tb_programacao
INNER JOIN tb_go ON tb_programacao.cod_go=tb_go.cod_go
INNER JOIN tb_funcionario ON tb_go.equi_func1_mat=tb_funcionario.matricula_qt
INNER JOIN tb_horario ON tb_horario.cod_funcionario=tb_funcionario.cod
WHERE tb_funcionario.cod=1
AND tb_programacao.data="2013-12-18"
AND tb_programacao.cod_go=1
AND tb_programacao.codprogramacao=1
GROUP BY tb_programacao.item;

我的 table :

tb_programação 
cod codprogramacao cod_go obra item tempoexposicao
1 |1 |1 |QUALIFICAÇÃO SOLDADOR |1 |01:00:00.000000
2 |1 |1 |QUALIFICAÇÃO SOLDADOR |1 |01:00:00.000000

tb_go
cod cod_go projeto equi_func1_mat
1 |1 |QUALIFICACAO DE SOLDADOR|0677

2 |1 |HCC 066/12 |0677

tb_funcionario
cod matricula_qt nome
1 |0677 |ABEL ALBUQUERQUE FERREIRA

tb_horario
cod cod_funcionario data
1 |2 |2014-01-01

3 |1 |2014-01-01

终于解决了,谢谢大家这就是我想要的查询

SELECT (SELECT SEC_TO_TIME( SUM( TIME_TO_SEC(tempoexposicao))) 
FROM tb_programacao AS t2
WHERE t2.item = t.item
) AS exposicao
FROM tb_programacao as t
INNER JOIN tb_go ON t.cod_go=tb_go.cod_go
INNER JOIN tb_funcionario ON tb_go.equi_func1_mat=tb_funcionario.matricula_qt
INNER JOIN tb_horario ON tb_horario.cod_funcionario=tb_funcionario.cod
WHERE tb_funcionario.cod=1
AND t.cod_go IS NOT NULL
AND t.data="2013-12-18"
AND t.cod_go=1
AND t.codprogramacao=1
GROUP BY t.clie_cod
ORDER BY CAST( t.cod_go AS SIGNED INTEGER ) ASC

最佳答案

当您从查询中删除这部分时会发生什么

AND tb_programacao.data="2013-12-18"

你也可以试试这个

SELECT SUM(tb_programacao.tempoexposicao) AS exposicao 
FROM tb_programacao
INNER JOIN tb_go ON tb_programacao.cod_go=tb_go.cod_go
INNER JOIN tb_funcionario ON tb_go.equi_func1_mat=tb_funcionario.matricula_qt
INNER JOIN tb_horario ON tb_horario.cod_funcionario=tb_funcionario.cod
WHERE tb_funcionario.cod=1
AND tb_programacao.data="2013-12-18"
AND tb_programacao.cod_go=1
AND tb_programacao.codprogramacao=1
GROUP BY tb_programacao.item;

关于mysql - 我的关节乘以我的总和结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21258012/

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