I am doing a row_number() over some data.
My problem is that I do not wnat to take into account data that is 0.
Here’s my data sample:
+-----------+-----+
| Alex | 1 |
| Liza | 2 |
| Harry | 0 |
| Marge | 24 |
| Bla | 0 |
| Something | 234 |
+-----------+-----+
Here’s what I want:
+-----------+--------+------------+
| name | number | row_number |
+-----------+--------+------------+
| Harry | 0 | 0 |
| Bla | 0 | 0 |
| Something | 234 | 1 |
| Marge | 24 | 2 |
| Liza | 2 | 3 |
| Alex | 1 | 4 |
+-----------+--------+------------+
as you can see the third column is the row_number()
this is what I have so far:
select name, number, row_number() over (partition by name order by name,number)
from myTable
How do I get the query above to return 0 for all 0's in the source data and not count the 0’s at all towards the row_number sequence?
Try this SQL Fiddle: