Link to home
Create AccountLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

number of reference mysql write sql in my sql to get the rank

the table below show  
 nae is ahead of  michale , cheery, victoria
susan is ahead of nae
david is ahead of susan



id      robert      headid
1      david      
2      nae              4
3      michale      2
4      susan      1
5      cheery      2
6      victoria      2
7      michele      2
8      nicole      3
9      taylor      2
10      rossom      2


how can I write the code in sql to show

name   rank
david    3
susan   2
nae       1

etc  

Avatar of skillszone
skillszone

Can you explain more about on what basis you would like to generate the Rank.
Avatar of MrTV

ASKER

a is a head of b
b is a head of c
c is the head of d


       rank
c        1
b        2
a        3



Avatar of MrTV

ASKER

a is a head of b   b is a head of c  c is the head of d


       rank
c        1
b        2
a        3

I have colum name and Hid (hierarchy id)
Hid related to id


id   name   Hid
1   a        
2   b        1
3   c        2
4   d        3
5   f        
6   g        5

How can I use sql statement to find this table

       rank
c        1
b        2
a        3
f        1
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer