I have the following query:
SELECT pa.codigo,
@rownum:[email protected]+1 AS nro
FROM presupuestosa pa , (SELECT @rownum:=0) r WHERE pa.obra=18
AND pa.empresa=1 ORDER BY codigo ASC
I wish that for each repeated code field, I can save the value 1 in rownum and otherwise rownonum have a value of 0, so I can use those values as undicators. That is, an example like this should yield as a result:
|Codigo |nro |
|3 | 0 |
|5 | 1 |
|5 | 1 |
|7 | 0 |
|8 | 0 |
|9 | 0 |
|11 | 1 |
|11 | 1 |
|12 | 0 |
I tried to use the case statement trying to compare the current row of the code with the next, but I do not know how to do it, if someone has any ideas, I would appreciate it