SQL practice troubles for beginner TYT -


i've study sql month , there many things i'm still cannot hold of. can me, plz provide results explaination, need understand future uses. list things cannot understand.

  • list id of managers , total number of employees reporting each of them. display result in descending order of total number of employees

i can do:

select employeenumber employees jobtitle '%manager%' union select employeenumber, count(*) employees reportsto 'which condition?' order count(*) desc 

can fill in after 'reportto', cant find condition that's working tyt

  • display offices , counts in each country think mean showing table every country , count total number of offices in country

i can do:

select country, count(*) offices group country union select country, officecode offices 

but results not expected

select reportsto, count(employeenumber) numberofemployees employees group reportsto 

will give count of employeenumbers report reportsto. not give managers nobody reporting to, have make join:

select a.employeenumber managernumber, count(b.employeenumber) numberofemployees employees left join employees b on (b.reportsto=a.employeenumber) a.jobtitle '%manager%' group a.employeenumber 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -