gpt4 book ai didi

mysql - 当其他列的其他结果相同时,如何对sql中的结果求和?

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

嗨,抱歉,如果我没有以正确的方式做问题

我有这个查询:

SELECT
t4.tar_nombre as nombre_tarea,
t2.rdi_fechacti as fecha_actividad,
t3.rea_hrstarea as horas_trabajadas

FROM
act_usuario t1
INNER JOIN
act_regisdiario t2
ON
(t2.usu_id = t1.usu_id)
INNER JOIN
act_registtarea t3
ON
(t3.rdi_id = t2.rdi_id)
INNER JOIN
act_tarea t4
ON
(t4.tar_id = t3.tar_id)
WHERE
t4.usu_id = 4
GROUP BY

t3.rea_id

ORDER BY
t2.rdi_fechacti

查询打印如下:

enter image description here

所以,当“fecha_Actividad”中存在相同的“nombre_actividad”时,我需要,这只显示一个“fecha_actividad”和“horas_trabajadas”的总和。

例如查询显示:

enter image description here

但我需要这个(因为相同的“nombre_tarea”在同一日期):

enter image description here

引用:

enter image description here

对不起我的英语。

最佳答案

分组后您可以简单地使用SUM(field)语法。

SELECT
t4.tar_nombre as nombre_tarea,
t2.rdi_fechacti as fecha_actividad,
t3.rea_hrstarea as horas_trabajadas,
SUM(t3.rea_hrstarea)
FROM
act_usuario t1
INNER JOIN
act_regisdiario t2
ON
(t2.usu_id = t1.usu_id)
INNER JOIN
act_registtarea t3
ON
(t3.rdi_id = t2.rdi_id)
INNER JOIN
act_tarea t4
ON
(t4.tar_id = t3.tar_id)
WHERE
t4.usu_id = 4
GROUP BY
t4.tar_nombre
ORDER BY
t2.rdi_fechacti

您还可以对分组结果使用其他函数。您可以找到它们here .

关于mysql - 当其他列的其他结果相同时,如何对sql中的结果求和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32575051/

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