Solve the Query plz

I am having employee table like
empId ename mgrid (empid id primary key,MgrId is foreign key ref of empId)
1 a null
2 b 1
3 c 1
4 d 2
5 e 2
6 f 3
i need the out put like
empId ename mgrid level
1 a null 1
2 b 1 2
3 c 1 2
4 d 2 3
5 e 2 3
6 f 3 3

SELECT    empId, ename, mgrid ,level
      FROM employees
START WITH mgrid IS NULL
CONNECT BY prior empId = mgrid;
SQL> SELECT     empno, ename, mgr, LEVEL
  2        FROM emp_test
  3  START WITH mgr IS NULL
  4  CONNECT BY prior empno = mgr;
     EMPNO ENAME             MGR      LEVEL
      7839 KING                           1
      7566 JONES            7839          2
      7788 SCOTT            7566          3
      7902 FORD             7566          3
      7698 BLAKE            7839          2
      7699 DAVID            7839          2
      7782 CLARK            7839          2
7 ligne(s) sélectionnée(s).
SQL> select * from emp_test;
     EMPNO ENAME      JOB              MGR HIREDATE          SAL       COMM     DEPTNO
      7698 BLAKE      MANAGER         7839 1981-05-01      20000                    30
      7566 JONES      MANAGER         7839 1981-04-02       5950                    20
      7699 DAVID      MANAGER         7839 1981-05-01      20000                    30
      7782 CLARK      MANAGER         7839 1981-06-09      20000                    10
      7839 KING       PRESIDENT            1981-11-17      10000                    10
      7902 FORD       ANALYST         7566 1981-12-03       6000                    20
      7788 SCOTT      ANALYST         7566 2087-04-19       6000                    20
7 ligne(s) sélectionnée(s).
SQL>

Similar Messages

  • Solve the query

    Hi all,
    We r working on SQL queries unable to solve teh below query.
    "Display the names of the highest paid programmers for each language"
    The table relating to the query is given below.
    PNAME DOB DOJ S PROF1 PROF2 SALARY
    anand 21-APR-66 21-APR-92 m pascal basic 3200
    altaf 02-JUL-64 13-NOV-90 m clipper cobol 2800
    juliana 31-JAN-68 21-APR-90 f cobol dbase 3000
    kamala 30-OCT-68 02-JAN-92 f c dbase 2900
    mary 24-JUN-70 01-FEB-91 f c++ oracle 4500
    nelson 11-SEP-65 11-OCT-89 m cobol dbase 2500
    partick 10-NOV-65 21-APR-90 m pascal clipper 2800
    qadir 31-AUG-65 21-APR-91 m assembly c 3000
    ramesh 03-MAY-67 28-FEB-91 m pascal dbase 3200
    resecca 01-JAN-67 28-DEC-90 m basic cobol 2500
    remitha 19-APR-70 20-APR-93 f c assembly 3600
    revathi 02-DEC-69 02-JAN-92 f pascal basic 3700
    vijaya 14-DEC-65 02-MAY-92 f foxpro c 3500
    Thanking in advance.
    Milind.

    you can achieve it using analytics.
    SQL> create table dummy(ename varchar2(32), salary number, language varchar2(32))
      2  /
    Table created.
    SQL>
    SQL> insert into dummy values('Scott', 5000, 'C')
      2  /
    1 row created.
    SQL> insert into dummy values('Tiger', 4000, 'C')
      2  /
    1 row created.
    SQL> insert into dummy values('Mark', 5000, 'Java')
      2  /
    1 row created.
    SQL> insert into dummy values('Smith', 4000, 'Java')
      2  /
    1 row created.
    SQL> insert into dummy values('White', 3000, 'Oracle')
      2  /
    1 row created.
    SQL> insert into dummy values('Blake', 25000, 'C++')
      2  /
    1 row created.
    SQL>
    SQL> set linesize 1000
    SQL> column ename format a32
    SQL> column salary format 9999999
    SQL> column language a32
    SP2-0158: unknown COLUMN option "a32"
    SQL>
    SQL> select * from (
      2  select ename, salary , language
      3       , row_number() over (partition by language order by salary desc ) high_sal
      4  from dummy)
      5  where high_sal=1
      6  /
    ENAME                              SALARY LANGUAGE                           HIGH_SAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    Scott                                5000 C                                         1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    Blake                               25000 C++                                       1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    Mark                                 5000 Java                                      1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    White                                3000 Oracle                                    1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    SQL> select ename, salary, language from (
      2  select ename, salary , language
      3       , row_number() over (partition by language order by salary desc ) high_sal
      4  from dummy)
      5  where high_sal=1
      6  /
    ENAME                              SALARY LANGUAGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    Scott                                5000 C                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    Blake                               25000 C++                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    Mark                                 5000 Java                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    White                                3000 Oracle                                                                                                             

  • Please solve the query

    Hi,
    I have a query which requires me to find the language that is known by only on programmer
    PNAME PROF1 PROF2
    anand pascal basic
    altaf clipper cobol
    juliana cobol dbase
    kamala c dbase
    mary c++ oracle
    nelson cobol dbase
    partick pascal clipper
    qadir assembly c
    ramesh pascal dbase
    resecca basic cobol
    remitha c assembly
    revathi pascal basic
    vijaya foxpro c
    The answer to this query is
    C++
    foxpro
    oracle.

    Hi APC,
    SQL> SELECT prof, p_cnt FROM(
      2  SELECT prof1 AS prof, count(pname) AS p_cnt
      3  FROM user_lang
      4  GROUP BY prof1
      5  UNION
      6  SELECT prof2 , count(pname)
      7  FROM user_lang
      8  GROUP BY prof2 )
      9  WHERE p_cnt = 1;
    PROF                      P_CNT
    assembly                      1
    basic                         1
    c++                           1
    clipper                       1
    foxpro                        1
    oracle                        1
    6 rows selected.You have to count AFTER the union... ;-)
    Regards,
    Gerd

  • Please help me solve the query

    CREATE TABLE SPONSER_UPDATION
    MEMBER VARCHAR2(12),
    SPONSER VARCHAR2(10),
    POINT NUMBER(10)
    MEMBER     SPONSER     POINT
    a     AS     10
    b     a     10
    c     b     10
    d     c     10
    e     d     10
    f     e     10
    i want a query or trigger on updating a single row all the row corresponding to it also gets updated example if i update a row with member f then its sponser e should also be updated and if sponser is is updatd then its sponser d should also be updated and if d is updated its spnser c should also be updated untill the last one through a single query
    i have written the trigger
    CREATE OR REPLACE TRIGGER points_updation
    AFTER UPDATE
    ON sponser_updation
    FOR EACH ROW
    DECLARE
    v_username varchar2(10);
    BEGIN
    update sponser_updation
    set
    point=point+10
    where
    :new.member=:old.sponser;
    END;
    after updation of any row error message is comming
    ORA-04098: trigger 'INVENT.SPONSER_UPDATION1' is invalid and failed re-validation
    thanks & Regards,
    anuj kumar singh!

    You can not insert, delete or update into this trigger type.
    try this:
    CREATE OR REPLACE TRIGGER points_updation BEFORE UPDATE ON sponser_updation FOR EACH ROW
    BEGIN
    if :new.member = :old.sponser then
    :new.point:=:new.point+10;
    end if;
    END;

  • Please solve the query in a single query

    1. display names of scott's collegue who earn more than scott
    using the emp table of scott schema

    As it's homework, we could always post you a really poor example of code like this:
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from emp
      3  where (1,empno) in (
      4                    select case when sal > (select sal from emp where ename = 'SCOTT') then 1 else 0 end as flag, empno
      5                    from emp
      6*                  )
    SQL> /
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7839 KING       PRESIDENT            17/11/1981 00:00:00       5000                    10But it would be better if you gave us an example of what you have done yourself, before we show you where you have gone wrong and how it can be improved.

  • Hello everybody,anyone can inform me plz if apple solve the problem of Maps

    hello everybody,anyone can inform me plz if apple solve the problem of Maps,

    i am in qatar ,i have iphone 4 (IOS 7) and after I determine the start and end point for the place where I want to go then i do route ,I receive this window :direction not available ,a route cannot be determined from this start location(this is old problem since ios4 maybe. plz any news about new solution .

  • Plz help in optimizing the query

    I have a query which is written to cater to the scenario that the entered start and end date do not overlap with the start and end date already present in the database records. Can someone help in optimizing this query. all inclusion and exclusion scenario's have to be taken care of.
    the query is as follows:
    SELECT COUNT(*) FROM CLAS WHERE TRIM(UPPER(CLAS_CDE)) =UPPER('timecheck') AND TRIM(UPPER(CLAS_TYPE_CDE))=UPPER('TEST_3')
    AND TRIM(UPPER(LANG_CDE))=UPPER('en')
    AND (
    (END_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
    OR
    (START_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
    OR (
    (START_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
    AND
    (END_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
    OR(('09/13/2007' BETWEEN TO_CHAR(START_DT,'MM/DD/YYYY') AND TO_CHAR(END_DT,'MM/DD/YYYY'))
    AND ('09/15/2007' BETWEEN TO_CHAR(START_DT,'MM/DD/YYYY') AND TO_CHAR(END_DT,'MM/DD/YYYY'))
    );

    I format your code in different way:
    SELECT COUNT(*)
    FROM CLAS
    WHERE TRIM(UPPER(CLAS_CDE)) = UPPER('timecheck')
    AND TRIM(UPPER(CLAS_TYPE_CDE))=UPPER('TEST_3')
      AND TRIM(UPPER(LANG_CDE))=UPPER('en')
       AND (
         (END_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
            OR
         (START_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
            OR (
              (START_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
              AND
              (END_DT BETWEEN TO_DATE('09/13/2007','MM/DD/YYYY') AND TO_DATE('09/15/2007','MM/DD/YYYY'))
         OR (
              ('09/13/2007' BETWEEN TO_CHAR(START_DT,'MM/DD/YYYY') AND TO_CHAR(END_DT,'MM/DD/YYYY'))
              AND
              ('09/15/2007' BETWEEN TO_CHAR(START_DT,'MM/DD/YYYY') AND TO_CHAR(END_DT,'MM/DD/YYYY'))
          );First thought that cross my mind it to check if changing this:
    UPPER('timecheck') to simple:
    'TIMECHECK' and do the same with other expressions with UPPER function.
    Peter D.

  • Please help me by solving the following query

    hi download the image from the above link and here i want latest dosi line count.....
    Please help me

    I think you don't need a plsql for this purpose ... you can find the sub total & final total in the query itself like
    select
         DOSI,
         ELEMENT_TYPE,
         SUM(USED)  USED
    from
         DOEMS_LICENSE_SUMMARY
    where
         DOSI in (DOSILIST)
    GROUP BY
         rollup(ELEMENT_TYPE, DOSI)      ** duplicate**

  • Please Solve The SQL Query

    Please Slove the Query as below:
              T1
    |     A1     |     A2     |
    |     TRUE     |     FALSE     |
    |     FALSE     |     TRUE     |
    |     TRUE     |     TRUE     |
    |     FALSE     |     TRUE     |
    Table Name is: T1 and it is having 2 columns A1 and A2.
    Question is:
    Using a simple SQL query try to get the total number of "TRUE" in the Table T1. Don't use any PL/SQL command,
    just use simple SQL command.
    Please write the full query.
    Manojit.

    select (Nvl(a.cnt_a1,0) + Nvl(b.cnt_a2,0)
    from (select count(1) CNT_A1 from t1 where a1 = 'TRUE') A
    (select count(1) CNT_A2 from t1 where as = 'TRUE') B
    Please Slove the Query as below:
              T1
    |     A1     |     A2     |
    |     TRUE     |     FALSE     |
    |     FALSE     |     TRUE     |
    |     TRUE     |     TRUE     |
    |     FALSE     |     TRUE     |
    Table Name is: T1 and it is having 2 columns A1 and A2.
    Question is:
    Using a simple SQL query try to get the total number of "TRUE" in the Table T1. Don't use any PL/SQL command,
    just use simple SQL command.
    Please write the full query.
    Manojit.

  • Missing Some Select input options the Query

    Hello all,
    Normally when i excute a query, it will ask for date range and year, fiscal period etc input options which i have to input to execute a given query. But  for one of the BWuser(sales guy) iam unable to see the fields, can anyone guess what cud be the problem. do you think its something to do with the BW authorization? any ideas to solve the problem are appreciated.
    Thanks
    SP

    Hi, you need to force the variables to be asked.
    Add &variable_screen=X at the end of the URL of the report. Check if then the values are requested.
    Hope this helps.
    Regards,
    Diego

  • Problem with exceptions in the query designer

    Hi all,
    i got this problem, there is a formula, than calculate  "A"   %A   "B", This bring a value %, ok.
    in my exceptions i got this ranges:
    1  to  99,4  Bad 9
    99,5 to 100  Good 1,
    i execute the query and this bring the results, when there is a line with value 99,5, this appear without color, the rest is ok,
    why this happend? whats the solution? please guys, i'll award you

    i m sorry the values are
    0 to 99,4 Bad 9
    99,5 to 100 Good 1
    i solve it by this way
    0  to 99,49999999999  Bad 9
    99,5000000001 to 100 Good 1
    i looks like the internal value of the KF is with a lot of decimal, the problem here is, when the value is 99,5 exactly, dont appear color, but i dont know how else solve it, any advice?

  • How to improve the query performance in to report level and designer level

    How to improve the query performance in to report level and designer level......?
    Plz let me know the detail view......

    first its all based on the design of the database, universe and the report.
    at the universe Level, you have to check your Contexts very well to get the optimal performance of the universe and also your joins, keep your joins with key fields, will give you the best performance.
    at the report level, try to make the reports dynamic as much as you can, (Parameters) and so on.
    and when you create a paremeter try to get it match with the key fields in the database.
    good luck
    Amr

  • In the report builder 6i when I choose the query  type as Express Query .....

    In the report builder 6i when I choose the query type as Express Query and go to next step where on pressing the connect button I am getting the following error.
    REP-6029 : Express error.
    How can I solve this problem ?
    Thanks
    Nanda Kishore

    DiId you download Oracle Reports Developer/Server Release 6i for Express, Files for Oracle8i for Windows NT from OTN?
    If so, could you provide me wih more information?
    Thanks
    Elaine

  • "The query was cancelled" error after upgrade from 10.1.3.3.3 to 10.1.3.4.2

    Hi,
    I was using OBIEE 10.1.3.3.3 /. After upgrading to 10.1.3.4.2 , the queries are not running ( long running queries alone) as expected. and so all the campaigns iwh tlong running queries are cancelled and the error message is seen in the xml log in Marketing jobs management.
    We have upgraded the OBIEE version from 10.1.3.3.3 to 10.1.3.4.2 yesterday after which the connectivites have been checked with SQLPLUS and they are working fine. But when the campaign has been loaded, the Analytics have received the request for the segment query and after longer run, the task has been cancelled with the error message "The Query was cancelled as mentioned below in the Job Stats
    <jobStats>
    <jobID>2</jobID>
    <jobType>WriteListFiles</jobType>
    <jobUser>userid</jobUser>
    <jobState>Error</jobState>
    <jobTotalMilliSec>1h 41m 21s 160ms</jobTotalMilliSec>
    <jobStartedTime>2012-03-22T08:06:13Z</jobStartedTime>
    <jobFinishedTime>2012-03-22T09:47:34Z</jobFinishedTime>
    <jobIsCancelling>N</jobIsCancelling>
    - <exception>
    <message>Job request of type "WriteListFiles" failed.</message>
    - <exception>
    <message>Error executing the list generation SQL.</message>
    - <exception>
    <message>Error in executing cursor for WorkNode (Id:0)</message>
    - <exception>
    <message>The query was cancelled.</message>
    </exception>
    </exception>
    </exception>
    </exception>
    </jobStats>
    Please let us know the suggestions
    So far, the unaccessedtimingrunoutminutes tag has been tried to set 50 under ODBC tag in instanceconfig.xml. and the defaulttimeoutminutes has been tried to set to 150 in the same instanceconfig.xml.
    along with that the rpd changes are done. For all the users apart from the Administrator, the timeout has been changedfrom 10 minutes to 150 minutes. But still that way is not working.
    The segments was fired with the Administrator login. So , if the timeout for admin login can be set, i assume that the problem might be solved. Please let us know ur suggestions here too.
    If that is the case, when we open rpd , only for Administrator user and group, the Permissions button is disabled. So i want to know how to change for Admin user settings in rpd..
    Please advice us on the same.
    Regards,
    Madasamy M.
    Edited by: Madasamy Murugaboobathi on Mar 26, 2012 1:40 PM

    The issue has been resolved by setting the following parameters
    <UnaccessedRunningTimeoutMinutes>120</UnaccessedRunningTimeoutMinutes>
    <DefaultTimeoutMinutes>120</DefaultTimeoutMinutes>
    <ClientSessionExpireMinutes>120</ClientSessionExpireMinutes>
    <ConnectionExpireMinutes>120</ConnectionExpireMinutes>
    <UIDefaultTimeoutMinutes>1440</UIDefaultTimeoutMinutes>

  • Error when using "inlist operator" in the query filter of Webi 3.1

    Hi,
    We are currently in the process of migrating Deski to webi (BOXI 3.1).
    The problem is, Deski is using the "inlist" operator which is working fine but after migrating to webi the inlist operator in the query filter is throwing the below error,
    *Error Message :*
    A database error occured. The database error text is: ORA-00907: missing right parenthesis. (WIS 10901)
    Appreciate your assistance on this.
    Thanks !
    Regards,
    Perialt

    Karthik ,
    Yes I am seeing an additional paranthesis in Webi SQL query.
    For example plz consider the product table below,
    SELECT
    Product.ID,
    Product.Name
    FROM Product
    WHERE
    Product.Name IN ( @Prompt('4) Name:','C','Product\Name-M',multi,free)  )
    As a work around in Custom SQL, If I remove the paranthesis the below query is running fine in webi
    SELECT
    Product.ID,
    Product.Name
    FROM Product
    WHERE
      Product.Name IN  @Prompt('4) Name:','C','Product\Name-M',multi,free) 
    But I want a permanent solution.

Maybe you are looking for

  • Creation of Service Notification  No for SO.

    Hi everyone, I am working on the User Exit for the first time. Kindly help me out with the following requirement. When a sales order is saved, create a service notification and link to the sales order header. To fulfill this requirement we need to us

  • Using Flash to generate code

    Hi i am interested in using adobe flash to generate a code out of the infomation a user inputs generally the idea is this 1. User inputs infomation such as age etc 2. a code gets generated 3. this code links in with the infomation that is given and i

  • No longer can open a password proteced document in Pages

    Hi, I have a password protected document that I've been using for a long time.  Now I am unable to open it.  I get a message saying that my password is wrong.  One thing I did a couple of days ago that has to do with passwords:  I attempted to make a

  • Itunes wont install/update

    I have tried three times to update itunes to the lates version, all three times it crashes my computer. So I deleted itunes and tried to insatll it from scratch, again it crashed my computer. I downloads just fine, then gets to install and just sits

  • Create Table with Compress for OLTP and error ORA-14464

    Hello, i have a Oracle-DB 11.2 and want to use Advanced Compression. I want to create a table: CREATE TABLE TD_GE_1990 ( "name_id" NUMBER(1,0), "name_txt" VARCHAR2(100 BYTE) ) COMPRESS FOR OLTP; But i get: SQL-Fehler: ORA-14464: Kompressionstyp nicht