Home > database >  SQL researchers sorted according to the department
SQL researchers sorted according to the department

Time:09-21

Staff table

Workuser
ID UserID DeptID

Corresponding department table
Dept

ID Name ParentID
Headquarters in 1 0
2 development 1
3 marketing 1
4 department of 0
5 customer service 4


Hope to be able to achieve according to the department personnel sort
Which department is divided into primary and secondary department
First cycle level of department personnel, recycling secondary department personnel
Who can help me, very urgent...

CodePudding user response:

Help ah, how have no one to talk to

CodePudding user response:

Headquarters and division level department, other three are the secondary sector

CodePudding user response:

First you send up to look at it, table structure associated two tables, and then order by line

CodePudding user response:

Don't know whether you have to be like this:
The select d.n ame, u.u serid
The from dept d, workuser u
Where d.i d=u.d eptid
The order by d.i d
;

CodePudding user response:

refer to the second floor smilysoft response:
headquarters and division level department, other three are the secondary sector.


yes

CodePudding user response:

If your database is oracle, can, in the following statement (low version of the oracle support to perform connect by table only)

The select level,
D.n ame,
U.u serid
The from dept d, workuser u
Where d.i d=u.d eptid
The order by d.i d
Connect by the prior d.i d=d.p arentid
Start with d.p arentid=0

CodePudding user response:

Note: write the order by d.i d this is removed

CodePudding user response:

refer to 6th floor msgtogcr response:
if your database is oracle, can, in the following statement (low version of the oracle support to perform connect by table only)

The select level,
D.n ame,
U.u serid
The from dept d, workuser u
Where d.i d=u.d eptid
The order by d.i d
Connect by the prior...

Thank you, what I use is sql2005

CodePudding user response:

Note: write the order by d.i d this is removed
  • Related