How do sum and Count in Mysql?

Asked

Viewed 499 times

0

I have a query which brings the number of lines of a certain fault.

select falhas, 
       count(falhas) 
  from tabela 
 where semana = 'semana-5' 
 group by falhas 
 order by count(falhas) desc;

The result brings the values below:

3 
2 
1
1
1

I need to add the first value with the second, and the sum of the two with the third, and so on. Does anyone know a way to do this in the MySQL.

what I wanted to display 3+2=5. takes the result 5+1 and so on line1 displays 5 Linha2 displays 6 line3 displays 7

or a way to break the string-based mysql_fetch_array.

  • Diego, what would the outcome look like? Is it simply the sum of the values, 3 + 2 + 1 + 1 + 1? Change the question and add the answer you expect.

1 answer

1

SELECT b.falhas, SUM(a.falhas)
FROM tabela AS a, tabela AS b
WHERE a.id <= b.id
GROUP BY b.falhas
ORDER BY b.falhas DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.