如何Sum()区分Row记录

时间:2017-06-29 06:35:48

标签: mysql sql h2

我有一个表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 个答案:

答案 0 :(得分:0)

您只需在查询中添加限制1