I want to create a function which returns how many levels the boss is above the person(calling the function).
Here is the way i would like to do it, but i don't quite know how SQL syntax works http://pastebin.com/dyDaGwf9
the table looks like this:
workerid name chefid
1 Bob
2 Alice 1
3 Joe 1
4 John 2
5 Dirk 4
6 Ralf 2
7 Lisa 1
8 Lyn 3
the final result upon calling the function should look like this
function call:
Select workerid, name, rankFunction(workerid) from workers;
workerid name rank
1 Bob 0
2 Alice 1
3 Joe 1
4 John 2
5 Dirk 3
6 Ralf 2
7 Lisa 1
8 Lyn 2
Would be great if somebody could shed some light,
Thanks!