Reputation: 239
What is the mysql query to get the below result from the table?. Addition in the amount column should be carried out based on the invoiceID.
Upvotes: 0
Views: 45
Reputation: 47492
SELECT @rownum := @rownum + 1 AS ID, InvoiceID, SUM(AMOUNT)
FROM <tablename>, (SELECT @rownum := 0) r
GROUP BY InvoiceID
Upvotes: 1
Reputation: 24076
try this:
select @i:=@i+1 AS id,a.*
from
(select InvoiceID,sum(Amount) as Amount
from your_table
group by InvoiceID)a,(SELECT @i:=0) r
Upvotes: 0