Count (*)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oraclemk
    New Member
    • Oct 2007
    • 4

    Count (*)

    how to display a employee name who have more emp working under him. we can consider the default emp table
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Kindly post what / how you have approached the problem.

    Comment

    • oraclemk
      New Member
      • Oct 2007
      • 4

      #3
      im getting the count of mgr distincly using count(mgr) and group by clause. but i have to retrive the empno of that employee.
      my goes here
      select mgr from (select count(mgr) cnt, mgr from emp group by mgr) e1 ;

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by oraclemk
        im getting the count of mgr distincly using count(mgr) and group by clause. but i have to retrive the empno of that employee.
        my goes here
        select mgr from (select count(mgr) cnt, mgr from emp group by mgr) e1 ;
        try the following query

        [CODE=oracle]select empno,ename from emp
        where empno=(select mgr from
        (select mgr,count(empno ) from emp
        where mgr is not null
        group by mgr
        order by count(empno) desc)
        where rownum<2)[/CODE]

        Comment

        Working...