Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Group directory

Author  Topic 

kwacz23
Starting Member

44 Posts

Posted - 2012-11-22 : 14:11:29
Hi,

I try to build something that can show how is under how in the company.
Please find my table below

id Employee id_supirior id_team
1 Adrian 10 1
2 Tomek 1 1
3 Mirek 1 1
4 Adam 10 2
5 Ewa 4 2
6 Marta 4 2
7 Iza 10 3
8 Kamil 7 3
9 Hugh 7 3
10 Martin NUll Null Boss of the whole company

So Martin is the top boss, under Martin we have 3 managers (id=1 Adrian,id=4 Adam, id=7 Iza)under them there is rest of the team.
I expect below result:

Name count Name count Name
Martin 3 Adrian 2 Tomek
Martin 3 Adrian 2 Mirek
Martin 3 Adam 2 Ewa
Martin 3 Adam 2 Marta
Martin 3 Iza 2 Kamil
Martin 3 Iza 2 Hugh

'Count= 3' Martin is Boss for 3 person
'Count=2' Adrian and Adam and Iza is boss for 2 person.

I hope this make sense. Could you be so kind and help me?

Regards
   

- Advertisement -