gpt4 book ai didi

php - 2 总和 php

转载 作者:行者123 更新时间:2023-11-29 05:09:40 24 4
gpt4 key购买 nike

我需要有关 2 个和数之和的帮助。好吧,我有显示用户总数的表格。在表的末尾,我需要制作显示所有数字总和的行。

表:

Table

所以在蓝色行我需要所有数字的总和。我的代码:

 $groupQuery =
"SELECT r.broj_rac AS racun, COUNT(stavka) AS stavka, d.naziv1 AS dobavljac, SUM(iznos_osnovica) AS osnovica, SUM(iznos_porez) AS porez, SUM(moze_se_odbiti) AS odbiti, SUM(nemoze_se_odbiti) AS neodbiti, SUM(neoporezivo) AS neoporezivo, SUM(ukupno) AS ukupno1, r.sveukupno AS sveukupno
FROM racuni AS r
LEFT JOIN dobavljaci AS d
ON d.sifra = r.dobavljac
WHERE partner = '".$_SESSION['sifra_partnera']."'
GROUP by broj_rac";

是否可以制作类似 SUM(SUM(ukupno AS ukupno1) AS ukupno2) 的东西?

最佳答案

看起来你想添加一个总行,而不是像其他答案所建议的那样对列求和,所以如果你只想包含一个总计 osnovicaporez 值:

$groupQuery =
SELECT r.broj_rac AS racun,
COUNT(stavka) AS stavka,
d.naziv1 AS dobavljac,
SUM(iznos_osnovica) AS osnovica,
SUM(iznos_porez) AS porez,
SUM(moze_se_odbiti) AS odbiti,
SUM(nemoze_se_odbiti) AS neodbiti,
SUM(neoporezivo) AS neoporezivo,
SUM(ukupno) AS ukupno1,
r.sveukupno AS sveukupno
FROM racuni AS r
LEFT JOIN dobavljaci AS d
ON d.sifra = r.dobavljac
WHERE partner = '".$_SESSION['sifra_partnera']."'
GROUP by broj_rac

UNION

SELECT 'TOTAL' AS racun,
'' AS stavka,
'' AS dobavljac,
SUM(iznos_osnovica) AS osnovica,
SUM(iznos_porez) AS porez,
'' AS odbiti,
'' AS neodbiti,
'' AS neoporezivo,
'' AS ukupno1,
'' AS sveukupno
FROM racuni AS r
LEFT JOIN dobavljaci AS d
ON d.sifra = r.dobavljac
WHERE partner = '".$_SESSION['sifra_partnera']."'"

UNION 的后半部分,您还可以对希望在总计行中汇总的任何其他字段执行聚合函数,例如 SUM(ukupno) AS ukupno1AVG(ukupno) AS ukupno1 如果您分别想要 ukupno 的总和或平均值。

关于php - 2 总和 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41632825/

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