Since mysql doesn't have support for windowing functions, we have to create our own group ranking for your table, and then another query to operate on the results.
select if(count(transaction) = 1, transaction, concat(min(transaction), '-', max(transaction))) transactions, sum(price) price
from (
select if(`transaction` = @prev + 1,
if(@prev := `transaction`, @rank, @rank),
if(@prev := `transaction`, @rank := @rank + 1, @rank := @rank + 1)
) gr,
`transaction`,
price
from table1, (select @rank := 1, @prev := 0) q
order by `transaction` asc
) q
group by gr
demo here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…