Board index » delphi » SQL and Self Referenced dataset

SQL and Self Referenced dataset

How can I query a self referenced dataset ?

For example, I have 3 tables :

Department -> dept_id, dept_name, parent_id
Employee -> emp_id, emp_name, dept_id, ctg_id
Category -> ctg_id, ctg_name, salary

Department is self referenced dataset.
All Id fields are of autoincrement type.

Now, I want to sum all salaries in some department.
Organization hierarchy might be of arbitrary length .

Thanks in advance.

__________________________________________
Miodrag Vincic            mvin...@eunet.yu
Belgrade,Yugoslavia    

 

Re:SQL and Self Referenced dataset


Quote
>Department -> dept_id, dept_name, parent_id
>Employee -> emp_id, emp_name, dept_id, ctg_id
>Category -> ctg_id, ctg_name, salary

>Department is self referenced dataset.
>All Id fields are of autoincrement type.

>Now, I want to sum all salaries in some department.
>Organization hierarchy might be of arbitrary length

Select D1.dept_id, Sum(D3.Salary)
From Employee D1 inner Join Category D2 on D1.ctg_id = d2.ctg_id
Group by D1.dept_id

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads