0

Payment Table

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.

enter image description here

3 Answers 3

1
SELECT @rownum := @rownum + 1 AS ID, InvoiceID, SUM(AMOUNT) 
FROM <tablename>, (SELECT @rownum := 0) r
GROUP BY InvoiceID
Sign up to request clarification or add additional context in comments.

Comments

0
select ID,InvoiceID, SUM(Amount)
from <table>
group by InvoiceID

Comments

0

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 


SQL Fiddel demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.