简体   繁体   中英

How to Sum() Distinct Row records

I have a table Purchase_table i have unique records in it with same Values, so am able to get the unique row using Group by Function, but my requirement i want so sum those records and show in single line With Total.

i used this query

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

output

[![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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM