Let say i have table
id|val
1 |1
2 |1
3 |2
4 |5
5 |2
6 |2
7 |2
How to get table like this:
2 | 1 |2
3 | 2 |1
4 | 5 |1
7 | 2 |3
I.e table in which third column is number of similar values in second column.
Sure i can do that using php or perl code, but i remmember it was posible by using sql variables only.