2012-09-25 185 views

回答

1
SELECT @rownum := @rownum + 1 AS ID, InvoiceID, SUM(AMOUNT) 
FROM <tablename>, (SELECT @rownum := 0) r 
GROUP BY InvoiceID 
0

試試這個:

select @i:[email protected]+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

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