Can someone break the logic of this request a little for me

What this global query essentially tells me. Could someone explain it to me a little.

WITH emp_count (eid, emp_last, mgr_id, mgrLevel, salary, cnt_employees) AS)

SELECT employe_id, last_name, manager_id, 0 mgrLevel, salary, 0 cnt_employees

Employees

UNION all

SELECT select, e.manager_id, r.mgrLevel + 1 mgrLevel, e.employee_id, e.salary, 1

cnt_employees

Emp_count r, e employees

WHERE e.employee_id = r.mgr_id)

Select * from emp_count;

I see only the managers here... ?

Also I was wondering why there wasn't more than 300 lines.

Thank you.

Hello

2776946 wrote:

What this global query essentially tells me. Could someone explain it to me a little.

WITH emp_count (eid, emp_last, mgr_id, mgrLevel, salary, cnt_employees) AS)

SELECT employe_id, last_name, manager_id, 0 mgrLevel, salary, 0 cnt_employees

Employees

UNION all

SELECT select, e.manager_id, r.mgrLevel + 1 mgrLevel, e.employee_id, e.salary, 1

cnt_employees

Emp_count r, e employees

WHERE e.employee_id = r.mgr_id)

Select * from emp_count;

I see only the managers here... ?

...

You tell me.  I don't know what data you use, what results see you, or what you consider a "Manager".

If there are rows in the table that are not "managers", then no, you see not only managers.  Each row in the table is included in the first half of the UNION, and there is nothing in the main query that removes all of these lines.

It seems that the query shows information about a hierarchy.  Assuming that each row in the table represents an employee and manager_id is a foreign key referencing employee_id number is unique, then all rows in the result set with mgrlevel = 0 represents a line in the table and all rows in the result set with mgrlevel = N (N > 0) will be the Manager of a person with mgrlevel = N-1.  Lines mgrlevel > 0 is not unique, and they're always going to duplicate some row with mgrlevel = 0.

Also I was wondering why there wasn't more than 300 lines.

Thank you.

Again, this depends on your data.

You may have more than 300 lines in the table.

Or you may have more than 150 lines, and they all have mgr_id that points to another row in the table.

Or you could have more than 100 lines and nearly all of them have a mgr_id and almost all these lines have a mgr_id and so on.

Tags: Database

Similar Questions

Maybe you are looking for

  • RocketRAID 4320 migration

    I just bought a new macpro refurb 2010 in Hong KONG. I have a raid array on my quad 2.5 powerpc running on a HighPoint Rocket Raid 4320. To move the map to the Macpro, I put the card in a PC and re flash a ROM EFI. That being said, there isn't much c

  • I upgraded to El Capitan, and now I've lost my photos! Help!

    Hi all! I have a problem, that can be very easy to fix. I've recently updated to OSX El Capitan. OK, I got that now iPhoto is replaced by pictures, which is great and so on BUT... I had many, many pictures saved and stored in iPhoto, and given that t

  • Can I configure find my mac if it executes window 10

    My MacBook and my brother "s retina pro 15 inch end 2013 I have this drive problem hard C02MD7T8FD56 is because change us it window?" Both our MacBook with the same problem. always have a message telling us this problem and save. And can we define Ma

  • I lost my icon of sky from my office?

    I have the icon for Sky on my desk for me to go straight to heaven when I connect.

  • Fujifilm finepix xp60 camera and windows 7

    All of a sudden my computer doesn't recognize and read the memory card from my camera or player.  It has worked well in the past and work on other computers.  I am really frustrated and would appreciate your help.