Hierarchy count of emp table by job title

Consider Emp table.
I want the hierarchical count by job title wise.
For president the count should be the total number of subordinates, i.e. the total number of emp's - 1 (the 1 is the president himself).
Like that any manager, the count is the total number of subordinates.
The output should be look like this:
Job Subordinates
President xx
Manager xx

I'm not sure what version you are looking into, but hierarchical total example is in 10g documentation (SQL Reference):
<quote>The following example uses a GROUP BY clause to return the total salary of each employee in department 110 and all employees below that employee in the hierarchy:
SELECT name, SUM(salary) "Total_Salary" FROM (
SELECT CONNECT_BY_ROOT last_name as name, Salary
FROM employees
WHERE department_id = 110
CONNECT BY PRIOR employee_id = manager_id)
GROUP BY name;
NAME Total_Salary
Gietz 8300
Higgins 20300
King 20300
Kochhar 20300
</quote>

Similar Messages

  • Fetching ename who are all having max(sal) in each of job from emp table

    hi all,
    i need a query to fetch all the ename who are all having maximum salary in each job category from emp table
    thankx in advance
    regrds,
    punith

    SQL> select ename,job,sal
      2  from emp
      3  order by job,sal desc;
    ENAME      JOB              SAL
    SCOTT      ANALYST         3000
    FORD       ANALYST         3000
    MILLER     CLERK           1300
    ADAMS      CLERK           1100
    JAMES      CLERK            950
    SMITH      CLERK            800
    JONES      MANAGER         2975
    BLAKE      MANAGER         2850
    CLARK      MANAGER         2450
    KING       PRESIDENT       5000
    ALLEN      SALESMAN        1600
    TURNER     SALESMAN        1500
    WARD       SALESMAN        1250
    MARTIN     SALESMAN        1250
    14 rows selected.
    SQL> select ename,job,sal from emp
      2  where sal in(select distinct max(sal) from emp
      3* group by job)
    SQL> /
    ENAME      JOB              SAL
    FORD       ANALYST         3000
    SCOTT      ANALYST         3000
    MILLER     CLERK           1300
    JONES      MANAGER         2975
    KING       PRESIDENT       5000
    ALLEN      SALESMAN        1600
    6 rows selected.
    SQL>Is this what you need ?

  • GETTING ROW COUNTS OF ALL TABLES AT A TIME

    Is there any column in any Data dictionary table which gives the row counts for particular table..
    My scenario is...i need to get row counts of some 100 tables in our database...
    instead of doing select count(*) for each table....is there any way i can do it?
    similary How to get column counts for each table..in database .For example
    Employee table has 3 columns...empid,empname,deptno....i want count(empid),
    count(empname),count(deptno) ...is there any easy way for finding all column counts of each table in data base? is it possible?

    Why does "select count(mgr) from emp" return null and not 13?Good question ;)
    Seems that xml generation in principle can't handle »counting nulls«:
    SQL> select xmltype(cursor(select null c from dual)) x from dual
    X                                                
    <?xml version="1.0"?>                            
    <ROWSET>                                         
    <ROW>                                           
    </ROW>                                          
    </ROWSET>                                        
    1 row selected.
    SQL> select cursor(select count(null) c from dual) x from dual
    Cur

    1 row selected.
    SQL> select xmltype(cursor(select count(null) c from dual)) x from dual
    select xmltype(cursor(select count(null) c from dual)) x from dual
    Error at line 1
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00229: input source is empty
    Error at line 0
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 1
    but
    SQL> select xmltype(cursor(select count(1) c from dual)) x from dual
    X                                                
    <?xml version="1.0"?>                            
    <ROWSET>                                         
    <ROW>                                           
      <C>1</C>                                       
    </ROW>                                          
    </ROWSET>                                        
    1 row selected.Looks like a bug to me ...

  • Count(*) for all tables

    Hi ,
    I want the Query to get the table name and count(*) display in excel like this.Can i get count(*) from metadata table .Please let me know ??
    ACCT 53
    ACCT_CHEQUE 45
    EMP 50
    DEPT 90

    Karthick_Arp wrote:
    A XML solution.
    This one is not mine. This question comes up often in this forum. And once i saw this answer. And i thought its really cool so just saved it in my Google Note Book ;)You need to update your google note book. It doesn't take account of Index Organised Tables.
    Based on answer from Laurent Schneider
    http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html
    SQL> select
      2    table_name,
      3    to_number(
      4      extractvalue(
      5        xmltype(
      6 dbms_xmlgen.getxml('select count(*) c from '||table_name))
      7        ,'/ROWSET/ROW/C')) count
      8  from user_tables
      9 where iot_type != 'IOT_OVERFLOW';
    TABLE_NAME                      COUNT
    DEPT                                4
    EMP                                14
    BONUS                               0
    SALGRADE                            5Edited by: BluShadow on Jul 8, 2009 12:00 PM

  • How to insert test data of 10,000 records into emp table

    Hi I'm new to oracle can anyone please help me in writing a program so that i can insert test data into emp table

    Hi,
    user11202607 wrote:
    thanks sanjay , frank . But how can i insert only 4 deptno's randomly and how can i insert only 10 managers randomly ,
    Sorry to pull Your legs and thanks for bearing my question. I want to insert into emp table where it has the empno, ename, sal, job, hiredate, mgr and deptnoThis should give you some ideas:
    INSERT INTO emp (empno, ename, sal, job, hiredate, mgr, deptno)
    SELECT  LEVEL                         -- empno
    ,     dbms_random.string ('U', 4)          -- ename
    ,     ROUND ( dbms_random.value (100, 5000)
               , -2
               )                         -- sal
    ,     CASE 
               WHEN  LEVEL =  1              THEN  'PRESIDENT'
               WHEN  LEVEL <= 4            THEN  'MANAGER'     -- Change to 11 after testing
               WHEN  dbms_random.value < .5  THEN  'ANALYST'
               WHEN  dbms_random.value < .5  THEN  'CLERK'
                                                 ELSE  'SALESMAN'
         END                         -- job
    ,     TRUNC ( SYSDATE
               - dbms_random.value (0, 3650)
               )                         -- hiredate
    ,     CASE
             WHEN  LEVEL > 1
             THEN  TRUNC (dbms_random.value (1, LEVEL))
         END                         -- mgr
    ,     TRUNC (dbms_random.value (1, 5))     -- deptno
    FROM     dual
    CONNECT BY     LEVEL <= 10                         -- Change to 10000 after testing
    ;The interesting part (to me, at least) is mgr. What I've done above is guarantee that the mgr-empno relationship reflects a tree, with the 'PRESIDENT' at its sole root. The tree can be any number of levels deep.
    Sample results:
    EMPNO ENAME        SAL JOB        HIREDATE  MGR DEPTNO
        1 GDMT        2800 PRESIDENT  30-AUG-04          2
        2 CVQX         400 MANAGER    24-MAY-06   1      2
        3 QXJD        1300 MANAGER    17-JUN-05   1      4
        4 LWCK        4800 MANAGER    15-JUN-06   2      2
        5 VDKI        3700 CLERK      08-SEP-01   4      2
        6 FKZS        2600 CLERK      18-DEC-06   4      1
        7 SAKB         700 ANALYST    30-JUN-00   5      4
        8 DVYY         300 ANALYST    22-SEP-01   2      1
        9 CLEO        2700 ANALYST    27-MAY-08   5      4
       10 RDVQ        3400 ANALYST    14-DEC-08   5      4For details on the built-in packages (such as dbms_random) see the [Parckages and Types manual|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_random.htm#i998925].

  • Select query on emp table

    Hi,
    How to find display the o/p like manager name under dependent employess same like parent child relation ship on noraml emp table:
    sample o/p:
    name job
    xx manger
    yy sales
    yy1 sales
    aa manager
    rr marketing
    rr1 marketing
    Thanks

    921306 wrote:
    so like this i need parent child relationship between the manager under employees....So join the parent entity with the child entity to create the parent-child relationship.
    As both entities are in the same table, this means joining the table to itself. E.g.
    SQL> select
      2          child.ename                     as CHILD,
      3          child.job                       as CHILD_JOB,
      4          nvl(parent.ename,'<none>')      as PARENT,
      5          parent.job                      as PARENT_JOB
      6  from emp parent,
      7       emp child
      8  where child.mgr = parent.empno (+)
      9  /
    CHILD      CHILD_JOB PARENT     PARENT_JO
    FORD       ANALYST   JONES      MANAGER
    SCOTT      ANALYST   JONES      MANAGER
    JAMES      CLERK     BLAKE      MANAGER
    TURNER     SALESMAN  BLAKE      MANAGER
    MARTIN     SALESMAN  BLAKE      MANAGER
    WARD       SALESMAN  BLAKE      MANAGER
    ALLEN      SALESMAN  BLAKE      MANAGER
    MILLER     CLERK     CLARK      MANAGER
    ADAMS      CLERK     SCOTT      ANALYST
    CLARK      MANAGER   KING       PRESIDENT
    BLAKE      MANAGER   KING       PRESIDENT
    JONES      MANAGER   KING       PRESIDENT
    SMITH      CLERK     FORD       ANALYST
    KING       PRESIDENT <none>
    14 rows selected.
    SQL> The basic concept is easy - define the parent entity, define the child entity, join the parent to the child.
    If some entities will not have parents (root entities), then an outer join is needed from the child entity to the parent entity.
    Simply because both entities are in the same table, does not change the logic or approach. It is perfectly valid to self-join a table.

  • Finding department and job title of employee in org model

    Hi all,
    Are there any Function Modules that can find out the department and job title (such as manager, director, etc) of an employee in SRM's org model (SRM4.0)?  What DB table(s) is this information stored in?
    Thanks!
    Jay

    Hi,
    You can use the FM "BBP_READ_ATTRIBUTES"  to read all the attributes of a user in the org structure.
    Other FM's;
    CRM_EMPLOYEE_GETORGUNIT
    DWP_GET_RESPONSIBLE_ORGUNITS
    BBPU_GET_ORGUNIT_AND_COUNTRY
    BBPU_GET_USERS_OF_ORGUNIT
    BBP_OM_USR_READ_WORKPLACE_ADDR
    RH_READ_OBJECT
    RH_READ_INFTY
    BBP_OM_STRUC_GET_ORG_FROM_POS
    BR,
    Disha.
    Do reward points for  useful answers.
    Do reward points for  useful answers.

  • Find EMP tables without SAL column

    We have EMP tables in several of our schemas. Some of these EMP tables have SAL column missing.
    How can i find the schemas whose EMP tables have a missing SAL column from DBA_TAB_COLS view?

    Hi,
    Here's another way, that only requires one pass throught the view:
    SELECT       owner
    FROM       dba_tab_cols
    WHERE       table_name     = 'EMP'
    GROUP BY  owner
    HAVING       COUNT (CASE WHEN column_name = 'SAL' THEN 1 END)     = 0
    ORDER BY  owner
    ;This might be more efficient, but, unless you have thousands of tables called EMP, you won't notice it. You might keep this tecnique in mind for similar problems where efficency is imporatant.

  • Unable to maintain job title for employees

    Hi friends
    we getting employees data from R/3 HR .but i am trying to assign  the job titles to employees in CRM systems through  relationship category but here  i am getting error "Maintenance is only possible via an external HR system".here if choose continues i am getting job title etc.. i can give input for job title but thing it is not saving. Could any one please suggest me how to do add the job titles.
    whether it can be possible change in CRM or not.
    If it is HR how could i add it.
    Earlier reply would be appreciated
    Thanks in advance
    Rao

    Rao,
    Have you looked at OSS Note 312090? Maybe you can find something here. The titles in HR is stored in another table as the BP titles. They should be replicated using an R/3 adapter object or kept the same as the BP titles.
    If nothing helps you could consider temporarily switch off the block for maintaining the employee in CRM. If I remember this is done by setting key PBPHR to OFF.
    Points if this helps.
    Regards,
    Nico

  • Nth Highest Salary from EMP table , need explaination

    I am new to the database world and hence learning queries at the initial stages. I want to retrieve the nth highest salary from the EMP table. I was not able to find out the answer by myself , so I searched on google. The following was the answer i got :
    SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
    Enter value for n: 2
    SAL
    3700
    Suppose the table contains salary in the following order :
    SAL
    2000
    3000
    3700
    4000
    3700
    2000
    So how come I will get the correct answer with the abov query ? I am not able to understand the part --- WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
    Specially the condition WHERE a.sal<=b.sal is very confusing to me. Can anyone help me please to understand the same.

    user12328699 wrote:
    I am new to the database world and hence learning queries at the initial stages. I want to retrieve the nth highest salary from the EMP table. I was not able to find out the answer by myself , so I searched on google. The following was the answer i got :
    SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
    Enter value for n: 2
    SAL
    3700
    Suppose the table contains salary in the following order :
    SAL
    2000
    3000
    3700
    4000
    3700
    2000
    So how come I will get the correct answer with the abov query ? I am not able to understand the part --- WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
    Specially the condition WHERE a.sal<=b.sal is very confusing to me. Can anyone help me please to understand the same.There is many better way to get the nth highest salary
    But still if you want to understand the same.
    Assuming the data is sorted in ascending order, then
    1) a.sal=2000, so a.sal<=b.sal results in count as 3 (not equal to user input)
    2) a.sal=3700, so a.sal<=b.sal results in count as 2 (equal to user input)
    3) a.sal = 4000 , so a.sal<=b.sal results in count as 1 (not equal to user input)
    Hence the answer is 3700
    Regards
    Anurag

  • How to get the select * from emp table output on the console  using java

    public class software {
          * @param args
         static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
         static final String DATABASE_URL = "jdbc:oracle:abc";
         private static Connection connection;
         private static Statement statement;
         public static void main(String[] args) {
              // TODO Auto-generated method stub
         try {
              System.out.println("-------THIS IS THE Class.forNameJDBC_DRIVER");
                   Class.forName(JDBC_DRIVER);
                   System.out.println("THIS IS THE Class.forNameJDBC_DRIVER");
                   connection = DriverManager.getConnection(DATABASE_URL, "abc",
                   "abc");
                   System.out.println("THIS IS THE connection abc ,abc");
                   statement = connection.createStatement();
                   //Query to find the values in the EMP table.
                   ResultSet resultSet = statement.executeQuery("SELECT * from EMP");
                   if(resultSet.next()){
                   System.out.println("THESE ARE THE VALUES IN EMP TABLE:"+resultSet);  /// How can i get all the values record wise on the  console ??????
                   resultSet.close();
         catch (ClassNotFoundException classNotFound) {
                   System.out.println("Driver not Found"+classNotFound.getMessage());
              } catch (SQLException sqlException) {
                   System.out.println("SQL Exception - bad sql");
                   System.out.println(sqlException.getMessage());
    }

    1sai
    Please assign the dukes here and in your previous threads.
    See [http://wikis.sun.com/display/SunForums/Duke+Stars+Program+-+How+it+Works]
    You are currently the all time career leader in un-awarded dukes, with including this thread 75 unawarded dukes for questions you marked as answered.
    It's even worse when you look and see that you have awarded many dukes as well. So you do know how to do it. You're just too lazy and rude to be bothered.
    Don't be a lazy wank.

  • C# - What's wrong with a table called JOBS? :(

    Post Author: Gee
    CA Forum: .NET
    Hi
    I've just moved up to .NET 2005. and am having a big problem right now with one report in particular.
    The report uses an Oracle table called "JOBS". It worked just fine in .NET 2003. Now though, it comes up with the dreaded field name not known error.
    So, I tried to just do a completely new report with just ONE field from the JOBS table on it. It doesn't want to know!
    I then copied (so it was IDENTICAL) the table structure and data to a new one called "JOBSTEST". The simple report worked (once I'd changed it to use the JOBSTEST fields of course)
    I deleted the original JOBS table, copied a new JOBS table from the JOBSTEST table and... it didn't work again!
    So, what's wrong with having a table called "JOBS"? Because that seems to be the problem!
    Oh... it works ok on the development machine. Just not any other. ALL other reports work fine!
    Thank you so much for your time in helping me

    Post Author: Gee
    CA Forum: .NET
    Hi
    I've just moved up to .NET 2005. and am having a big problem right now with one report in particular.
    The report uses an Oracle table called "JOBS". It worked just fine in .NET 2003. Now though, it comes up with the dreaded field name not known error.
    So, I tried to just do a completely new report with just ONE field from the JOBS table on it. It doesn't want to know!
    I then copied (so it was IDENTICAL) the table structure and data to a new one called "JOBSTEST". The simple report worked (once I'd changed it to use the JOBSTEST fields of course)
    I deleted the original JOBS table, copied a new JOBS table from the JOBSTEST table and... it didn't work again!
    So, what's wrong with having a table called "JOBS"? Because that seems to be the problem!
    Oh... it works ok on the development machine. Just not any other. ALL other reports work fine!
    Thank you so much for your time in helping me

  • How to get row count(*) for each table that matches a pattern

    I have the following query that returns all tables that match a pattern (tablename_ and then 4 digits). I also want to return the row counts for these tables.
    Currently a single column is returned: tablename. I want to add the column RowCount.
    DECLARE @SQLCommand nvarchar(4000)
    DECLARE @TableName varchar(128)
    SET @TableName = 'ods_TTstat_master' --<<<<<< change this to a table name
    SET @SQLCommand = 'SELECT [name] as zhistTables FROM dbo.sysobjects WHERE name like ''%' + @TableName + '%'' and objectproperty(id,N''IsUserTable'')=1 ORDER BY name DESC'
    EXEC sp_executesql @SQLCommand

    The like operator requires a string operand.
    http://msdn.microsoft.com/en-us/library/ms179859.aspx
    Example:
    DECLARE @Like varchar(50) = '%frame%';
    SELECT * FROM Production.Product WHERE Name like @Like;
    -- (79 row(s) affected)
    For variable use, apply dynamic SQL:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Rows count all tables:
    http://www.sqlusa.com/bestpractices2005/alltablesrowcount/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • How to display required data from emp table?

    Hi every one, this is my first post in this portal. I want display the details of emp table.. for that I am using this SQL statement.
    select * from emp where mgr=nvl(:mgr,mgr);
    when I give the input as 7698 it is displaying the corresponding records... and also when I won't give any input then it is displaying all the records except the mgr with null values.
    1)I want to display all the records when I won't give any input including nulls
    2)I want to display all the records who's mgr is null
    Is there any way to incorporate to include all these in a single query..

    Hi,
    937440 wrote:
    Hi every one, this is my first post in this portal. Welcome to the forum!
    Be sure to read the forum FAQ {message:id=9360002}
    I want display the details of emp table.. for that I am using this SQL statement.
    select * from emp where mgr=nvl(:mgr,mgr);
    when I give the input as 7698 it is displaying the corresponding records... and also when I won't give any input then it is displaying all the records except the mgr with null values.
    1)I want to display all the records when I won't give any input including nulls
    2)I want to display all the records who's mgr is null
    Is there any way to incorporate to include all these in a single query..It's a little unclear what you're asking.
    The following query always includes rows where mgr is NULL, and when the bind variable :mgr is NULL, it displays all rows:
    SELECT  *
    FROM     emp
    WHERE     LNNVL (mgr != :mgr)
    ;That is, when :mgr = 7698, it displays 6 rows, and when :mgr is NULL it displays 14 rows (assuming you're using the Oracle-supplied scott.emp table).
    The following query includes rows where mgr is NULL only when the bind variable :mgr is NULL, in which case it displays all rows:
    SELECT     *
    FROM     emp
    WHERE     :mgr     = mgr
    OR       :mgr       IS NULL
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL it displays 14 rows.
    The following query includes rows where mgr is NULL only when the bind variab;e :mgr is NULL, in which case it displays only the rows where mgr is NULL. That is, it treats NULL as a value:
    SELECT     *
    FROM     emp
    WHERE     DECODE ( mgr
                , :mgr, 'OK'
                )     = 'OK'
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL, it displays 1 row.

  • How can i see the callers special information like Job Title, Company name, and may be notes?

    I need to see the caller’s  special infos in call screen.  Like Company name, Job Title?
    Please dont say me, “put these info to name&surname field”, because that, i’m useing Outlook Contact and i cannot change it.
    I tried some special programs like (Call Screen (caller id Screen) prog: https://itunes.apple.com/tr/app/call-screen-caller-id-screen/id446742417?l=tr&mt =8 ) but it changes the persons picture but it not refresh itself, if i change info.
    Lots of people asked same question but there is no any exact answer.
    I think it must be a metbod for the seeing this special info in call screen.
    Oldest Nokia and Blackberry model phone shows  this info, More smart phone iPhone can shows it i think. Please show me, how can i see this infos in call screen.

    Other than finding an App to do what you want, or putting the info in the name field, you can't, as this is not a feature of the stock iOS.

Maybe you are looking for

  • HTTPS connection with client certificate not working in spartan

    Spartan does not show certificate for the user to select when I click the https link. The certificates (taken from a smartcard) are indeed present in the user CertStore. It works with IE 11 and Chrome. Has somebody any suggestions ? Thanks.

  • Optical drive vibrates when burning files

    When I burn a dvd or cd in my optical drive (DVD R/W) the whole drive vibrates so hard that I have to clamp it in place with my hand.  Sometimes it will not burn the items selected and sometimes it does.  I have ourchased a new (used) dvd optical R/W

  • Citrix Metaframe1.8 implementation with Oracle Apps 11i.

    We are considering implementing Citrix Metaframe 1.8 with our existing 11i implementation. As Oracle does not support Citrix as a platform to run Jinitiator, could anyone share their experience with a similar implementation, and maybe advice me on ke

  • Menu - Submenu - and Sub Sub Menu

    on my site, for some reason, the "sub sub" menu buttons called "deal 2, and deal 3 to the right of the business cards button, only work (turning green for the rollover) when the "sub sub" menu buttons in the "business flyers" menu are not there. If I

  • Select Until Next Word is broken?  Ctrl+Shift+Right Arrow

    I don't use Dreamweaver all that often, and this is one reason why.  But it's finally gotten on my nerves long enough that I thought I would ask about it.  What can I do to fix Dreamweaver so that "Select Until Next Word" works as it should-the way i