0
Suppose the following table:
id -- ano
1 -- 2014
2 -- 2014
3 -- 2014
4 -- 2015
5 -- 2015
6 -- 2016
7 -- 2016
8 -- 2016
9 -- 2016
I would like to get a list with a sequential count/numbering of rows grouped per year, as follows in the example:
id -- ano -- count
1 -- 2014 -- 1
2 -- 2014 -- 2
3 -- 2014 -- 3
4 -- 2015 -- 1
5 -- 2015 -- 2
6 -- 2016 -- 1
7 -- 2016 -- 2
8 -- 2016 -- 3
9 -- 2016 -- 4
Note that this is not a simple count, where a Count+group by would solve, but rather a line numbering, where each year the counter goes back to 1.
Any idea how to do that?
This can be done directly in the programming language instead of in the query, it is probable until it becomes more performatic when adjusting in the loop, which language uses?
– Guilherme Nascimento
I’m using c#, but I managed to reach a solution using variables in mysql that I will post now.
– Alexandre Ruiz
C# with what? Asp.net-mvc or
MySqlDataAdapter.fill()
or netcore with Entityframeworkcore? If you can give some relevant detail so that it is possible to formulate a suggestion this will facilitate.– Guilherme Nascimento