gpt4 book ai didi

mysql - 如何对不同行记录求和

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

我有一个表Purchase_table,其中有具有相同值的唯一记录,因此我能够使用Group by函数获取唯一行,但我的要求是因此,对这些记录求和并用总计显示在单行中。

我使用了这个查询

select date , invoiceno ,orgname as vendor , 
invoice_value as taxable_value ,sum(cgst_value) as cgst ,sum(sgst_value) as sgst ,
sum(igst_value) as igst , invoice_value +cgst_value +sgst_value +igst_value as Invoice_value from purchase_table group by invoiceno union all select 'Total', '','', sum(invoice_value), sum(cgst_value), sum(sgst_value), sum(igst_value), sum(invoice_value +cgst_value +sgst_value +igst_value) from purchase_table group by invoiceno order by date, invoiceno

输出

[![This is the output of my query having Total in many line, i want the output in one line with all unique qroup by records][1]][1]

最佳答案

您只需在查询中输入限制 1

关于mysql - 如何对不同行记录求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44817948/

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