Issue of SQL Hieraerchical

Oracle Enterprise Version 11.2.0,.3

I need to write a hierarchical query to give me registration with the version of henriq # if the record is a child of a parent. If the folder has no children so I need the parent to save himself.

{code}

Employee:

ID ParentId Version #
11
21
322
433
544
61
755
81

For example:

so I need to show the sheet 1 1 recordID did no parentid

RecordID 8 has no parentid so I need to see the card 8

RecordID 2 has 4 levels of children, I need to get the record with max version 5 i.e Recordid 7

2            1

3-2-2

4-3-3

5-4-4

7-5-5

Expected result

ID Parentid Version

1            1

7-5-5

8            1

Hello

Maybe you want something like this:

SELECT id

parentid

version #.

The EMPLOYEE

WHERE CONNECT_BY_ISLEAF = 1

START WITH parentid IS NULL

CONNECTION BY parentid = PRIOR id

;

The output I get from your sample data is:

PARENTID EXTRA STRONG VERSION

--- ---------- ----------

1                    1

1                    1

7          5         5

6                    1

8                    1

Did you mean to have 2 identical rows in the table with id = 1?  If so, but you only you one of them appear in the results, use SELECT DISTINCT.

Why you don't want to ID = 6 in the output?

When you talk about "max version" do you mean the highest value, or the deep hierarchy?  In other words, if you have changed the row with id = 4 to be

INSERT INTO EMPLOYEE (id, parentid, version #)

VALUES (4, 3, 300) - version # was originally 3

/

the version 'max' in the output would still be 5, or would it be 300?

Tags: Database

Similar Questions

  • During database migration issues in SQL Serever

    Hello

    In single database migration in SQL Server, what are all the possible questions, that allows us to get.

    Please help me on this.

    RD

    SQL server questions should be asked on the Technet site

    http://social.technet.Microsoft.com/forums/en-us/home

  • Base date regarding the issue of SQL

    create table emp (empname varchar2 (35), join_date date);

    Insert into emp VALUES ('JOHN', TO_DATE (March 23, 2005 09:00 ',' DD-MON-YYYY HH24 '));

    insert into emp VALUES ('HANS', TO_DATE (February 14, 2012 14:00 ',' DD-MON-YYYY HH24 '));

    commit;

    SQL > alter session set nls_Date_format = 'DD-MON-YYYY HH24. "

    Modified session.

    SQL > select * from emp;

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    HANS FEBRUARY 14, 2012 14:00

    To find all employees who have joined the date of March 23, 2005, I need to do the following.

    Y at - it a shorter version for this request?

    SQL > select * from emp where JOIN_DATE > TO_DATE (March 23, 2005 00:00 ') AND JOIN_DATE < TO_DATE (March 24, 2005 00:00 ');

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    Hello

    N.Page wrote:

    create table emp (empname varchar2 (35), join_date date);

    Insert into emp VALUES ('JOHN', TO_DATE (March 23, 2005 09:00 ',' DD-MON-YYYY HH24 '));

    insert into emp VALUES ('HANS', TO_DATE (February 14, 2012 14:00 ',' DD-MON-YYYY HH24 '));

    commit;

    SQL > alter session set nls_Date_format = 'DD-MON-YYYY HH24. "

    Modified session.

    SQL > select * from emp;

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    HANS FEBRUARY 14, 2012 14:00

    To find all employees who have joined the date of March 23, 2005, I need to do the following.

    Y at - it a shorter version for this request?

    SQL > select * from emp where JOIN_DATE > TO_DATE (March 23, 2005 00:00 ') AND JOIN_DATE< to_date="" ('24-mar-2005="">

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    You mean > = instead of >, to register the join_dates that are exactly 12:00:00 AM on March 23.  Keep< at="" the="" end;="" you="" don't="" want="" anything="" from="" march="" 24,="" and="" you="" don't="" want="" between="" for="" the="" same="">

    What you posted is the fastest way.  Use DATE instead of TO_DATE literals, it is a bit shorter and just as fast.

    SELECT *.

    WCP

    WHERE join_date > = DATE '' 2005-03-23

    AND join_date<  date="">

    ;

    May be the shortest path (which will be slower):

    SELECT *.

    WCP

    WHERE TRUNC (join_date) = DATE '' 2005-03-23

    ;

    It's slower because we need to call a function for each row in the table, and (potentially much larger) this means that you cannot use an index on join_date.

  • What is the right answer, is that this issue is sql?

    Hello.. Please I need a correct answer to this question...

    See the exhibition and examine the structure of the PRODUCTS table.

    Using the PRODUCTS table, you publish the following query to generate names, current list prices, and

    price list for all these products whose list price falls below $10 after that a discount of 25% reduced

    on this subject.

    SQL > SELECT prod_name, prod_list_price,.

    prod_list_price - (prod_list_price *. 25) "DISCOUNTED_PRICE".

    PRODUCTS

    WHERE discounted_price < 10;

    The query generates an error.

    What is the reason of the error?

    Has the parentheses should be added to frame the entire expression.

    B - double quotes should be removed from the column alias.

    Column alias C - replace it with the expression in the WHERE clause.

    Alias column D - The should be capitalized and closed with the double quotes in the WHERE clause.

    Took me 5 seconds to see that in Google: alias in where clause that exactly answers your question.

  • issue backup SQL vCenter

    Can I backup the database Sql 2005 of the vCenterserver with a netbackup client like truncates logs then.

    Hello

    Honestly, I just create a SQL job to do the backup of the database and then simply leave netbackup backup your sql backup.  I did a post on how to make a backup of the database of Veeam, but the same thing applies to vCenter - it's just what I'd do...

    http://blog.mwpreston.NET/2011/11/28/Dr-for-your-Dr-solution-get-a-SQL-backup-of-your-Veeam-backup-replication-database/

  • Delicate issue of SQL

    SQL experts: I need to write a query to search for empid that has at least one fake folder

    example: empid 1 is bad since its start_date (record 3) 05/01/2013 is before it expires 15/02/2013 (sheet 2). Similarly, empid 3 is bad since 12-12 - 2012(record 7) of start_dt is before its date of expiry 31/12/1999 (chart 6).

    There may be a number of entries for each empid.

    empid start_dt               end_dt
    1     01-01-2013          01-10-2013
    1     01-11-2013          02-15-2013
    1     01-05-2013          12-31-9999
    
    2     01-01-2013         12-31-9999
    
    3     01-20-2012         1-15-2012
    3     01-31-2012         12-31-9999
    3     12-12-2012         01-01-2013
    I would be grateful for any input?

    Oracle Version 11.2.0.3

    Thank you
    Kevin

    Published by: Kevin_K on March 5, 2013 15:53
    select distinct
     empid
    from (
    select
     empid
    ,case
     when lag(end_dt,1, start_dt) over (partition by empid order by start_dt) > start_dt
     then 1
     end flag
    from your_table
    )
    where
    flag = 1
    

    Edited by: chris227 the 05.03.2013 16:32

    Edited by: chris227 the 05.03.2013 16:32

  • Issue of SQL Plan Management

    Hello

    I have a question concerning the presence of 'Accepted' indicator (values or NOT) that is displayed by the function dbms_xplan.display_sql_plan_baseline.

    It is my understanding of the documentation of Oracle SQL plan does not become part of a plan SQL database until it is accepted by the process of evolution or manual loading in the base line. How is it possible to have a plan to be part of a reference that is not accepted? If the dbms_xplan.display_sql_plan_baseline function is used to display more than plans that are in a reference database and that are only in the story?


    Thanks for your thoughts on this.

    Richard

    PS. I use Oracle 11.1.0.7

    Welcome to the forum!
    >
    How is it possible to have a plan to be part of a reference that is not accepted? If the dbms_xplan.display_sql_plan_baseline function is used to display more than plans that are in a reference database and that are only in the story?
    >
    View code that you use to call the function and the result you get.

    Depending on how you call the function, and what plans are available, you will get different results. For example
    >
    plan_name
    Name of plan. It identifies a specific plan. Value default NULL means that all the plans associated with identified SQL statement are explained and displayed
    >
    You specify this setting? If this isn't the case, then all THE plans could include plans that have not been accepted.

    Section 15.5 display SQL Plan baseline in the Performance Tuning Guide contains an example of this and displays two plans: an accepted and the other not.
    http://docs.Oracle.com/CD/E11882_01/server.112/e16638/optplanmgmt.htm

    It's really the history display that includes all plans.

  • I need issue of SQL/PLSQL for practice

    Hi all

    I need to question of SQL/PLSQL for practice; could everything on send me the URL.

    I need only the PDF file.

    Thank you
    Gregory

    Here is the link for the link of PL/SQL oracle

    http://www.Oracle.com/pls/db111/portal.portal_db?selected=5&frame=

    IN the section of SQL and PL/SQL language, there is the language Pl/SQL.. PDF reference .you can download... its preety good to start.

  • Performance issues for sql developer

    1. DB connection leaving open a SQLNavigator has no impact on the resources of the DB and the performance?

    If you got all the lines, then should be no impact on the database.

    You can close the table editor/query results grids just to be sure if you do not know.

  • Issue of SQL, to learn

    Can someone explain to me what / / means?

    CASES WHERE 1 = 1 THEN ELSE 0 0 END as the column alias_de_colonne

    or

    CASES WHERE 1 = 1 THEN 0 1 END as the column alias_de_colonne ELSE

    ?

    There are 3 tables that join each other and I select a few columns of A, B and C,.
    but then there are over this case and it is not referencing a Table at all, and I'm trying to
    to understand what this does? :-) with that 1 = 1 company, thank you!

    Thank you!
    CASE WHEN 1=1 THEN 0 ELSE 1 END as column column_alias
    

    Well, if I ask you "true or false: 1 = 1'? What would you say?

    A condition like '1 = 1' is used when you want to always set to TRUE. Similarly WHEN 1 = 0 will always evaluate to FALSE.

    In the code above "0" will always be returned since 1 'will always be equal to 1'. The ELSE and the rest is just to complete the CASE statement if you do not have a syntax error.
    This query returns a line

    select * from emp where 1=1 and empno = 7369
    
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    7369,SMITH,CLERK2,7902,12/17/1980,4567,,20
    

    and it does not work

    select * from emp where 1=0 and empno = 7369
    
  • Configuration of replication between SQL 200 and SQL 2005

    0

    I use two SQL servers

    Server1 = (SQL2000 8.0.2194)

    Server2 = (SQL 2005 9.0.5000)

    Server1 is my editor and Server2 is my Distributor and Subscriber

    For some reason, I managed to create server1 and Server2 server publishing server, but I can't to server2 sonfigure as a Distributor on server1 see error below

    Error 18483: Could not connect to the server XXXX because
    'distributor_admin' is not defined as a remote login on the server

    What could be the cause?

    Thank you very much

    Best regards

    Vusi RAHARISON

    Hey Vusi Radebe,.

    Please reach out to the IT Pro audience in the community support with replication SQL Server TechNet. The link below will take you to the SQL Server instance that focuses on replication issues:
    TechNet - SQL Server - replication

  • SQL Server 2008 installation, error in PerfMonCounterNotCorruptedCheck

    When I install SQL Server 2008 Expression I get the following error;

    The performance counter registry hive is corrupted. To continue, you must repair the performance counter registry hive. For more information, see http://support.microsoft.com/kb/300956.

    I have not been able to correct this page and the link doesn't refer to Vista. Comment & solution?

    Hi Jon Thor Johannsson,

    For a more specialized on issue of SQL Server help, post your request here

    SQL Server forums
    http://social.technet.Microsoft.com/forums/en/SQLExpress/threads

  • Bug of NLS in SQL Developer 4.1 on mac

    Hi all

    I downloaded sqldeveloper 4.1.1.19.59 for mac os x from the Web site. When you try to connect to an Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64 bit Production database I get an error ORA-12705, the same error as shown in this issue: update SQL Developer 4.0.1 cannot connect (error ORA-12705) . I tried the NLS settings in my sqldeveloper than those of my database, but nothing happened.

    Currently, the problem was solved by using an older version of sqldeveloper. Specifically, 4.0.2 version.

    Signs of what's going on?

    Kind regards.

    Julian

    Although not specific to OS X, another debate is better: Developer SQL 4.1.1.19.59: error opening Database 9i or package procedure

    So, to summarize...

    1 use a version of SQL Developer (4.0.3 or lower) which comes with a 11.2.0.3 (or less) JDBC. That should help to interact with Oracle 9i.

    2. install a 11.2.0.3 Oracle instant client and configure SQL Developer 4.1.1 to use rather than the 12.1 driver

    See Tools > Preferences > Database > advanced > use Oracle Client... Configure...

  • SQL Developer ignoring NLS preferences

    I'm having and issue with SQL Developer Version 3.2.20.09 where my settings in the preferences of NLS Date and time are not used for the nls_session_parameters.

    I changed the Date Format to DD-MM-RRRR HH24:MM:SS in preferences by default, but when I run new sessions format remains the default DD-MON-RR as a game being checked when I run

    SELECT *.
    OF nls_session_parameters

    If I run

    ALTER session set NLS_DATE_FORMAT = ' HH24:MM:SS RRRR-MM-DD ".

    I can get information to display the way I want it, but it resets whenever I start a new session.

    Hello
    change your settings to RRRR-MM-JJ HH24:MM:SS for HH24:Mi:SS of DD-MM-RRRR and see

    Concerning
    SANAE

  • ESXi &amp; Microsoft SQL Server 2000

    Hello

    I was recently charged with the project of implementation of VMware ESXi to work on a new blade for our system HP C3000 Blade of companies. Before making a purchase, I was asked to ensure that VMware Esxi is able to support Microsoft SQL Server 2003 on Windows 2003 server R2 on a blade virtualized.

    I did some research and can only subjects already seen related to SQL Server 2005, but never 2000.

    Can someone help me on this issue and let me know if this is doable and if so are there issues running SQL Server 2000 on a virtualized (I.E.) machine Timing or delay?

    I appreciate any help anyone can provide.

    Thank you

    Jserra

    Great!  Good luck.  A DB that small and I wouldn't worrry about creating a LUN RAW either.

    Please mark my first 'Proper' or 'Useful', reply to encourage frequent detachment!

    Sven

Maybe you are looking for

  • Spam

    I keep getting emails that appear to come from Apple, send my bills and fees for music and apps that I have not bought. Is this a spam? It happened for about 4 months, with a couple that runs through every month. Help appreciated, H

  • Complain: Incomplete information given in the "using the spellchecker"how to"

    I use Firefox 4.0 on Windows XP. I wanted to install a spell checker on Firefox Add-on to enable automatic spell check as I have in my Google Chrome. I searched on the net and landed on this article ( http://support.mozilla.com/en-US/kb/Using%20the%2

  • HP ENVY 17 t-k000: HP ENVY 17 t-k000 brightness in win 10

    There was a sort of automatic update recently and all of a sudden I can't change the brightness of the screen.  The brightness keys don't work either.  I tried everyting, installing and uninstalling drivers.  Although now I am confused bc drivers, it

  • Equium P300 is IRQL_NOT_LESS_OR_EQUAL message

    Please help, I have an Equium P300-16 t, now I went to turn on the laptop & was facing a blue screen goes all in curls just restart & end up with blue screens even when you click on repair windows you get a choice of repair windows or start windows n

  • HP 700-327c: Bluetooth

    I can't connect my Bluetooth (I-Phone or EU-Miniboom speaker) devices THA bluetooth recognizes the device, but will not pair up with either. the Iphone up to the UE_MiniBoom pairs so I don't think the problen is with devices. I uninstalled the Blueto