Sum with condition.

Hello guys I have a simple query, but it just dosent seem to work. I have a column that I would only add another column is between a range, but I keep getting '0', even if a part of the range has values. can someone please point out what is obvious.

Thanks in advance
select nvl(sum(fgbopal_14_ytd_actv),0)  from fgbopal
where fgbopal_fund_code = '400002' 
and nvl((fgbopal_acct_code),0) between '7000' and '7019'  
and nvl((fgbopal_acct_code),0) between '7046' and '7177'
FYI If part of the range has a value but the other party does not, I always get a '0 '.
Help!

Hello

user633029 wrote:
Hello guys I have a simple query, but it just dosent seem to work. I have a column that I would only add another column is between a range, but I keep getting '0', even if a part of the range has values. can someone please point out what is obvious.

Thanks in advance

select nvl(sum(fgbopal_14_ytd_actv),0)  from fgbopal
where fgbopal_fund_code = '400002'
and nvl((fgbopal_acct_code),0) between '7000' and '7019'
and nvl((fgbopal_acct_code),0) between '7046' and '7177'

FYI If part of the range has a value but the other party does not, I always get a '0 '.
Help!

The last two conditions cannot be true at the same time.
If, on a line, ggbopal_acct_code is between '7000', and '7019', then it will not be between ' 7046 'and ' 7177'.
If it's between '7046' and '7177', then it will not be between ' 7000 'and ' 7019'.

Maybe you wanted to say:

select  nvl(sum(fgbopal_14_ytd_actv),0)  from fgbopal
where   fgbopal_fund_code = '400002'
and     (   fgbopal_acct_code between '7000' and '7019'
        or  fgbopal_acct_code between '7046' and '7177'
        )

The following has nothing to do with your problem, but I got rid of the NVL in the WHERE clause, because NVL (x, '0') will be between "7000' and '7019' (or '7046' and '7177') if and only if x itself is between '7000' and '7019' or between ' 7046 '(and ' 7177')."
If x is a VARCHAR2 (or other string) and you use NVL (for example, WHERE NVL (x, '0') BETWEEN ' 0 'and ' 2999') then don't forget to quote the '0'. The two arguments of NVL should both be of the same type, strings or two numbers.

Published by: Frank Kulash, July 12, 2009 12:32

I just saw Michaels response.
Both

nvl (sum (fgbopal_14_ytd_actv), 0)

and

sum (nvl (fgbopal_14_ytd_actv, 0))

will produce the same results. The first way will be a little more efficient, because NVL will not need to be called once.

Published by: Frank Kulash, July 12, 2009 12:54

Tags: Database

Similar Questions

  • Calculation of the sum with condition

    Hello
    I start with BI publisher, and I want to take a NAP with condition.

    My report output XLS, I haves columns, named ACCOUNT_TYPE and TREE_NODE and MOENTARY_AMOUNT_03 that are my PS query fields

    I want to sum only when a condition is true.

    <? xdofx:If ACCOUNT_TYPE = 'R' AND TREE_NOD = 'TEST' then
    Sum (MONETARY_AMOUNT_03)
    end if? >

    This does not,
    could you help me?

    thaks!

    You should do this:

  • power-sum with condition group

    Hello
    I'm fighting with these totals.
    I can't understand the syntax <? sum (current - group (/AMOUNT))? > condition AMOUNT > 100.
    What I want him to have Total of any amounts that are greater than 100 for example. This 100 is supposed to be variable.

    I tried some things that have been proposed in the forum, but all raise error.

    You can try some thing like that

    [100])? >

    can you send me your model you use.

    E-mail: [email protected]

  • join with condition

    Hi all

    Is there a possible way to cross the join with condition?

    I want something like this:

    Table A: custid, accu_id, sum

    CustID, accu_id unique =

    CustomerID amount accu_id

    10 25 400

    10 35 447

    10 29 420

    20 30 510

    30 35 472

    .

    .

    .

    Table b: accu_id, description

    accu_id description

    shoes 25

    Book 29

    30 computer

    pen 35

    Note: in table A, it is a mismatch of the accu_id values that do not use. Please, take into account this.

    I want to see all the columns in the TABLE B for each custid in A. TABLE (something like cross join but with ONE article.) The following query does not work.

    Select * from a right join B on A.accu_id = B.accu_id;

    10-25

    10-29

    10-30

    10-35

    20-25

    20-29

    20-30

    20-35

    30 25

    30 29

    30 30

    30-35

    What should I do for this?

    Thanks in advance

    Use partition outer join:

    with a (too)

    Select double union all 10 custid, accu_id 25, amount 400

    Select 10,35,447 from all the double union

    Select 10,29,420 from all the double union

    Select 20,30,510 from all the double union

    Select double 30,35,472

    ),

    b like)

    Select accu_id 25, "shoe" description of all the double union

    Select 29, 'book' from dual union all

    Select 30, 'computer' from dual union all

    Select 35, 'pen' from dual

    )

    Select a.custid,

    a.accu_id,

    a.amount,

    b.

    a

    by (a.custid) partition

    right join

    b

    On a.accu_id = b.accu_id

    order of a.custid,

    a.accu_id

    /

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    10 25 400 shoe
    10 29 420 book
    10 35 447 pen
    10 computer
    20 30 510 computer
    shoe 20
    book 20
    20                       pen
    30 35 472 pen
    30 shoe
    30 book

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    30 computer

    12 selected lines.

    SQL >

    SY.

  • SQL with conditions

    Hello

    I need to generate a summary table with conditions. Here are the details:

    create the table tb_class (classId number (5), studentNum number (5));

    create table tb_grade (classId number (5), gradeNum number (5)):

    insert into table values tb_class (101, 100);

    insert into table values (201, 102) tb_class;

    insert into table values (102, 103) tb_class;

    insert into table values tb_grade (101, 1);

    insert into table values (102, 1) tb_grade;

    insert into table values (201, 2) tb_gradfe;

    I would like to get the total number of students registed in a specific shade with a SQL, the result is expected as follows:

    GradeNum studentNumRegistered studentNumNonRegisted

    1                         203                                      102

    2                         102                                      203

    Is that what you are looking for?

    WITH subsum AS
     (SELECT tb_grade.gradenum,
             SUM(tb_class.studentnum) AS students
      FROM   tb_class
      JOIN   tb_grade ON tb_grade.classid = tb_class.classid
      GROUP  BY tb_grade.gradenum)
    SELECT subsum.gradenum,
           SUM(subsum.students) AS studentnumregistered,
           SUM(subsum1.students) AS studentnumnonregistered
    FROM subsum
    JOIN subsum subsum1 ON subsum1.gradenum != subsum.gradenum
    GROUP  BY subsum.gradenum;
    
  • Where to write the condition in the design of workflows with conditional step?


    Hello

    Again, I wish BP and workflow with contitional design stage.

    I had designed BP and workflow.

    As directed by the user for Udesigner guide, I had added trigger before the condition step.

    But I do not understand where to set the Condition to test?

    If I need to write the condition in triggering elemt itsel... How to proceed?

    for example, I want to write the condition as cost of Tota > = 100000, it must follow a path and if fails to another path.

    The conditions of triggers are specified in the workflow settings.  After you have created a new configuration, open it and click on the settings tab.  You will see a tree structure of the workflow with conditional branches.  Click a conditional branch to set the parameters for the trigger for this route condition.

  • Reactive layouts: publish multiple Sites with conditional Builds and which connect

    I hope that someone can provide a simple solution to publish problems I've had with adapted presentations when you try to publish several sites with conditional builds. Essentially, I want to be able to have an index page that links to one of the two variants of the published sites that I called 'General' and 'specific '. When I click on the 'general' link I want to not open the site which was published with a conditional for all these subjects compilation labeled as 'general' and when I click on the 'link' want it to open the site which was published using a conditional version for 'specific '.

    Here are the steps I took to create sites and can't seem to get to bind correctly:

    Table of contents, topic Creation and tagging content

    1. Creates a Table of contents.
    2. Added 2 topics in the Table of contents. The first topic, I called "general" and the second issue I called, 'specific '.
    3. I then click with the right button on the "general" and selected subject Tag to build conditional apply. From there, I've created a new tag called "General".
    4. I repeated this process to create the specific tag, but do a right-click on the 'specific' theme and the creation of a new tag called "specific".

    Layouts reactive and edited the sites based on the conditional tags

    1. Created sensitive presentation using the standard layout and content generated without any conditional builds.
    2. Duplicated sensitive put in page and gave him the content of 'general' then it is generated using the conditional, "General" version If the finished publication published content has shown that the 'general' subject, as expected.
    3. I then repeated the same process for the specific content and content using the version parole, generated 'specific '. When over content published showed that the subject marked as 'specific' as expected.

    Added an Index page to the table of contents

    1. Created a new topic to serve as the launch page.
    2. Added a 'general' hyperlink called for the launch of the general "theme found in the general publishes from the resource manager.
    3. Added a hyperlink called 'specific' to the launch of the general "theme found in the specific issues from the resource manager.
    4. I then republish the sensitive standard layout site.

    From this point, it gets stuck and won't open properly published Web sites. I don't know why it won't launch hyperlinks correctly. Is there something I'm missing? Let me know if you do not want to see my files. I will be gladly their.

    OK, thanks a lot for the capture screen. They help more than you realize.

    So here's one of the biggest mistakes I think that you have done so far. You use the resource manager to link to published results. If it is technically possible to do, I'm pretty sure Adobe never planned for it to be used this way.

    It may help to think in terms of creation of food products. I have long considered as RoboHelp to be very much like working in my kitchen. All consumables (heading text in the headings, images, HTML pages, etc.) are just as raw ingredients. (Eggs, milk, flour, etc.). The places of storage (hard drive) it's like the pantry and the fridge. And RoboHelp provides facilities to easily combine ingredients to create the different recipes.

    This next bit will be somewhat exaggerated, but bear with me. Maybe you have one or more neighbors and all you want to share some common "ingredients". If you set the things where each of you have access to a wine cellar and a shared refrigerator. Maybe you do a Dutch sauce killer. You create it and place in the refrigerator, then your other participants have access through the common "fridge". This is exactly what the resource manager is intended to help.

    Now assume that you create something like cookies chocolate chip and you keep in the refrigerator. Well, that's fine, but you don't want to use cookies to chocolate chip already baked in a recipe that might call for cookie dough. But that's what happens when you take an exit and place in a place intended for raw ingredients. And you will see the strange behavior. Prepare for these cookies chemically changes them so that cookies already are significantly different from the dough used to create them. Similarly, you don't want to take one or more output files and reuse in a project source.

    So in your case, you run an index file and that fires events to produce the output. All should be well. But when you click on the links to open topics, topics are intended to show up more in the right panel. Think of the picture of how works of image on a TV. The moment that link you to something intended to fill the screen, he is forced into this smaller area on the right. If you end up with what you see in the last picture.

    I suggest the following steps.

    First, REMOVE your resource manager exits.

    REMOVE all links that can point here.

    Output records where people will consume copy your projects. (The web server)

    Then figure either the parent (.. /.. / somefolder/somefile.htm) path to other systems or the absolute path (http://www.whatever.com) and to link the projects in this way.

    Sorry, but without seeing the installation of first hand, it is difficult to say what should be these paths.

    I hope this was helpful... Rick

  • How to avoid duplicates on a column with condition

    Hi all

    I need some advice here. At work, we have an Oracle APEX application that allow the user to add new records with the decision of the increment automatic number based on the year and the group name.

    Said that if they add the first record, group name AA, for 2012, they get the decision number AA 1 2013 as their record casein displayed page of the report.

    The second record of AA in 2013 will be AA 2 2013.

    If we add about 20 records, it will be AA 20 2013.

    The first record for 2014 will be AA 1 2014.

    However, recently, we get a claim of the user on two files of the same name of group have the same number of the decision.

    When I looked in the history table and find that the time gap between 2 record is about 0.1 seconds.

    In addition, we have the correspondence table which allows the user admin update the sequence number start with the restraint that it must be greater than the maximum number of the current name of the current year.

    This boot sequence number and the name of the group is stored together in a table.

    And in some other case, the user can add a decision duplicate for related record number. (this is a new feature)

    The current logic of the procedure to add the new record on the application are

    _Get max record table with selected group name (decision_number) and the current year.

    _INSERT in the folder table the new record came with the decision to number + 1

    _ update sequence number of the number of the decision just added.

    So instead of utitlising the process of editing the built-in automatic table of the APEX, I write a procedure that combine all three processes.

    I have run some loop for continually perform this procedure, and it seems that it can generate autotically new decision unique number with time about 0.1 second difference.

    However, when I increase the number of entry to 200 and let two users run 100 each.

    If the time gap is about 0.01 second, double decision numbers are displayed.

    What can I do to prevent duplicate?

    I can't just apply a unique constraint here for three columns with condition because it can be duplicated in some special conditions. I don't know much about the use of lock and its impact.

    This is the content of my procedure

    create or replace

    PROCEDURE add_new_case)

    -ID just use the trigger

    p_case_title IN varchar2,

    p_year IN varchar2,

    p_group_name IN VARCHAR2,

    -decisionnumber here

    p_case_file_number IN VARCHAR2,

    -active

    p_user in VARCHAR2

    )

    AS

    NUMBER default_value;

    caseCount NUMBER;

    seqNumber NUMBER;

    previousDecisionNumber NUMBER;

    BEGIN

    -execution immediate q '[alter session set nls_date_format = "dd/mm/yyyy"]';

    SELECT count (*)

    IN caseCount

    OF CASE_RECORD

    WHERE GROUP_ABBR = p_group_name

    AND to_number (to_char (create_date, "yyyy")) = to_number (to_char (date_utils.get_current_date, "yyyy"));

    SELECT max (decision_number)

    IN previousDecisionNumber

    OF CASE_RECORD

    WHERE GROUP_ABBR = p_group_name

    AND to_number (to_char (create_date, "yyyy")) = to_number (to_char (date_utils.get_current_date, "yyyy"));

    IF p_group_name IS NULL

    THEN seqNumber: = 0;

    ON THE OTHER

    SELECT Seq_number INTO seqNumber FROM GROUP_LOOKUP WHERE ABBREVIATION = p_group_name;

    END IF;

    IF caseCount > 0 THEN

    default_value: largest = (seqNumber, previousdecisionnumber) + 1;

    ON THE OTHER

    default_value: = 1;

    END IF;

    INSERT INTO CASE_RECORD (case_title, decision_year, GROUP_ABBR, decision_number, case_file_number, active_yn, created_by, create_date)

    VALUES (p_case_title, p_year, p_group_name, default_value, p_case_file_number, 'Y', p_user, sysdate);

    -Need to update the sequence here also

    UPDATE GROUP_LOOKUP

    SET SEQ_NUMBER = default_value

    WHERE the ABBREVIATION = p_group_name;

    COMMIT;

    EXCEPTION

    WHILE OTHERS THEN

    Logger.Error (p_message_text = > SQLERRM)

    , p_message_code = > SQLCODE

    , p_stack_trace = > dbms_utility.format_error_backtrace

    );

    LIFT;

    END;

    Many thanks in advance,

    Ann

    It's easier to solve for the case, while p_group_name is not null. In this case, you update a GROUP_LOOKUP line, so that you can select to update this line at the beginning, to prevent cases of two for the same group added at the same time. To do this, change the selection of GROUP_LOOKUP to:

    SELECT Seq_number INTO seqNumber FROM GROUP_LOOKUP WHERE ABBREVIATION = p_group_name for an updated VERSION OF the SEQ_NUMBER;

    and move this to be the first thing that did the procedure - before it has CASE_RECORD lines.

    In the case when p_group_name is set to null, you have some object to be locked. I think the best you can do is to lock the entire table GROUP_LOOKUP:

    the table lock in exclusive mode GROUP_LOOKUP wait 100;

    The '100 expectation' means that he will wait until 100 seconds before giving up and trigger an error. in practice, that is expected to only wait a moment.

    Exclusive mode allows others to read, but not to update the table.

    UPDATES and the LOCK of the TABLE will be updates of other sessions wait for this transaction to validate. Queries from other sessions are not affected.

    The locks are released when you commit or roll back.

  • XMLTable to extract columns with conditional path does not

    Hello

    I am on 11.2.0.3 and I need to extract columns on a section of XML with conditions on, but I get "ORA-00907: lack the right parenthesis", so I think that the way I go about it is not supported or that I have somehow the wrong syntax or something.

    This is a very simplified what I'm trying to do (there could be several different entries in the < sets1 > and < sets2 > sections and they might be in different orders, is not as if I can always choose the first or the last):

    with sample_data as (select 1 id,
                                xmltype('<root>
                                           <sets1>
                                             <set1><set_name>name1</set_name><set_val>val1</set_val></set1>
                                             <set1><set_name>name2</set_name><set_val>val2</set_val></set1>
                                           </sets1>
                                           <sets2>
                                             <set2><set_name>name3</set_name><set_val>val3</set_val></set2>
                                             <set2><set_name>name4</set_name><set_val>val4</set_val></set2>
                                           </sets2>
                                         </root>') xml_doc from dual)
    select *
    from   sample_data sd,
           xmltable('<root>' passing sd.xml_doc
                    columns col1 varchar2(10) path 'sets1/set1[set_name=''name1'']/set_val',
                            col2 varchar2(10) path 'sets1/set1[set_name=''name2'']/set_val',
                            col3 varchar2(10) path 'sets2/set2[set_name=''name4'']/set_val') x;
    

    What I'm trying to get:

    COL1  COL2  COL3
    ----  ----  ----
    val1  val2  val4
    

    I know that I could separate the < set1 > and < set2 > nodes in their own xmltypes xmltable on it and then join them and make the necessary pivoting, etc., but when I try to start that against only 1000 lines, db do not love and ended my session! Therefore, I'm looking for a more elegant way to do it.

    Is there a way to do this in a XMLTABLE? Pointers are very welcome!

    It solves your problem of sample request and you get the output that show you.

     with sample_data as (select 1 id,
                                 xmltype('
                                            
                                              name1val1
                                              name2val2
                                            
                                            
                                              name3val3
                                              name4val4
                                            
                                          ') xml_doc from dual)
     select x.*  -- change
     from   sample_data sd,
            xmltable('/root' passing sd.xml_doc  -- change
                     columns col1 varchar2(10) path 'sets1/set1[set_name="name1"]/set_val',  -- change
                             col2 varchar2(10) path 'sets1/set1[set_name="name2"]/set_val',  -- change
                             col3 varchar2(10) path 'sets2/set2[set_name="name4"]/set_val') x;  -- change
    

    As you can see, I've marked the lines that I've changed.  The error you saw came to use two single quotes in the COLUMN XPath instead to use double quotes.  Then I changed the XPath expression in the XMLTable brackets as well.

    I'm confused on what the columns you really want overall, in terms of how you know which values you want, or did you mean that you want something random sets1 and sets2.

    You store the XML file in a column of XMLType SECUREFILE BINARY, right?  It seems that you made previous visits, but just double check.

  • Conversion with conditional text in table

    I take the first steps in converting unstructured structure image. A single document is fairly clean except for one question: my structure breaks around conditional text in tables. (The tables have a their own, but the conditional text questions f3ew seems to make the problem worse) I don't know how it should be treated. Structure tags are displayed in the view below.

    condTable.png

    And here's the view of the Structure:

    TblStruct.png

    Is this something that can be implemented with a qualifier, and if so, how? In addition, in the mapping of conversion table, is there any dependency order, as well, on which appears the conditional text element?

    Martine

    As Michael says, a conversion table does not convert the structure conditions. In a structured document, we apply, removes, shows and hides the conditions in the same way as is done on an informal document. The only difference is that you can select entire items and treat them with conditions.

    In a sense, FrameMaker treats conditions like processing instructions. If you need to export a document structured in XML and view it with a browser or a text editor, you can find instructions for treatment that punctuate the beaches of conditional text.

    So, once again as Michael, the text says conditional is not breaking your structure. It is superimposed on the structure.

    Van

  • Encoded text with conditional compilation still tags appear in TOC even if the label is "excluded".

    I use TCS2, Windows XP.

    After you have created a book in FM and coding with conditional compilation tags, I imported HR. When I generate, I output the value tag:

    NOT NoOUtput AND NOT internal AND NOT printed - I want to generate my external, webhelp online help. And it works like a charm. Except that:

    • In the table of contents, I can still see the stars for the things that are "internal" - when I click on it, they're not going anywhere... but I don't want them to appear in the table of contents!

    It seems to exclude from the index and search. I don't know that miss me just a step, or something...


    Browsing the forums I found this... http://forums.Adobe.com/message/751847#751847 -I don't know if it is still applicable, because it seems to allude to RH6 (which is a bit far from the 8 HR that I use)...

    Any help is appreciated!

    TIA,

    Adriana

    @Daggins - that's what I was talking about! I knew it was there somewhere ;>)

    @adrianaharper - if it doesn't work properly in PDF files that you create on the FM band; what the TOC looks like FM? You're just pulling in HR when you import/link right? If the faulty internal topics are appearing in the table of contents of the FM, then expect them to appear in HR too. You must kill them, FM or kill them in HR.

  • Field of conditional sum with checkboxes

    I am creating a total field contingent in a PDF form created by me which will only add cost in total ONLY if the box is checked.  Another disadvantage to this is one of the fields (number of monitors), I am eager to multiply by the field notes, which is a field required number on there.

    All of them are select___

    Here are all the names of FQDN (towards the bottom):

    Check the boxes:

    • selectiPhone
    • selectSwipe
    • selectMonitor
    • selectDesktop
    • selectLaptop
    • selectiPadCell
    • selectiPad
    • selectPhone

    Fields costs:

    • CostiPhone
    • CostSwipe
    • CostMonitor
    • CostDesktop
    • CostLaptop
    • CostiPadCell
    • CostiPad
    • CostPhone

    The notes field that will calculate this is "NotesComputer Monitor in notes".

    Then add them all in TOTAL COST

    Please see below for the screenshot.

    2015-10-07_0920.png

    The script is the "JavaScript custom calculation" for the field "TOTALCOST.

    Conditional Sum

  • Run the query in accordance with condition

    Oracle 10g version

    Hi gurus

    I have the following data

    Examples of data

    SELECT DeptNo FROM scott.emp

    UNION ALL

    SELECT EmpNo FROM scott.emp

    ;

    Now what I want is I want to execute conditionally of those surveyed, something like below:

    If list_item = 'I', then run below

    SELECT DeptNo FROM scott.emp

    otherwise run below

    SELECT EmpNo FROM scott.emp

    End if;

    ------

    I want to keep the union all and run the query under the terms...

    Set a long tank (max 4000)

    L_WHERE_CLAUSE

    Use it in your application as a substitution variable by prefixing with &

    WHERE & L_WHERE_CLAUSE

    Assign the value into a pl/sql block (trigger, formula column)

    IF condition THEN

    L_WHERE_CLAUSE: = '1 = 1';

    ON THE OTHER

    L_WHERE_CLAUSE: = '1 = 2';

    END IF;

    Now, among the options that have been suggested to you and the information you provided, I think the solution of Solomon should be easier. Just refer to the column list_item has a link within your query variable (assuming that this and the query where list_item belongs are related, for example, there is a join between them)

    SELECT DeptNo FROM scott.emp, t

    WHERE: list_item = 'l '.

    UNION ALL

    SELECT EmpNo FROM scott.emp, t

    WHERE nvl(:list_item,'x')! = « l »

  • Master detail relationship with condition enforcement in the secondary table

    Hello

    I have two tables are Dept (Master), PMCs (Detail). I have to show emp details with somewhere condition.

    Ex;

    I have a "Dept_effect_date" field in the dept table. When I m showing PGE details in the Details view, it must the EMOS who are hired after the dept_effect_date.

    Sainaba.

    Hello

    The request of the employees table looks very good. Although it seems more logical to get the service id of the employeesEO instead of DepratmentsEO.

    The next step should be to create a viewLink between the DepartmentsVO and the EmployeesVO based on the service ID field.

    Once you have done this, add the EmployeesVO as a DepartmentsVO child in yout request module (and it will appear as such in the DataControl), so use these your to create master/detail table.

    Updating the data based on the selected master will be automatically managed by ADF.

    Kind regards

    Elias.

  • Hierarchical queries - problem with condition "begins by".

    Hi people

    I play with the connection by and start with clause and am faced with a particular problem which I can not solve...

    My data set is:

    Create table dates_q
    (start_date date,
    end_date date)
    /
    

    REM INSERTING into dates_q
    Insert into dates_q ("START_DATE","END_DATE") values (to_date('01-JAN-14','DD-MON-RR'),to_date('10-JAN-14','DD-MON-RR'));
    Insert into dates_q ("START_DATE","END_DATE") values (to_date('11-JAN-14','DD-MON-RR'),to_date('20-JAN-14','DD-MON-RR'));
    Insert into dates_q ("START_DATE","END_DATE") values (to_date('10-MAR-14','DD-MON-RR'),to_date('20-MAR-14','DD-MON-RR'));
    Insert into dates_q ("START_DATE","END_DATE") values (to_date('21-MAR-14','DD-MON-RR'),to_date('31-MAR-14','DD-MON-RR'));
    Insert into dates_q ("START_DATE","END_DATE") values (to_date('01-APR-14','DD-MON-RR'),to_date('10-APR-14','DD-MON-RR'));
    

    Now I basically just want to get your hands on hierarchical queries and working with the syntax of various...

    What I now want is, start with the date of April 1 as my start date and work backward to build my 'tree '. The condition of my tree is between two rows; my start and end dates differ from 1 day. If they do not; I don't want these records in my tree.

    And using sys_connect_by_path, I want to get all the way from the root.

    Thus, for example,.

    SELECT a.*,
           sys_connect_by_path(start_date, '|'),
           LEVEL lvl
      FROM dates_q a
     CONNECT BY PRIOR end_date = (start_date - 1)
    

    I get the following output

    START_DATEEND_DATESYS_CONNECT_BY_PATH(START_DATE,'|')LVL
    01.01.201410.01.2014| 1 JANUARY 141
    11.01.201420.01.2014| 1 JANUARY 14 | JANUARY 11, 142
    11.01.201420.01.2014| JANUARY 11, 141
    10.03.201420.03.2014| MARCH 10, 141
    21.03.201431.03.2014| MARCH 10, 14. MARCH 21, 142
    01.04.201410.04.2014|10-MAR-14|21-MAR-14|01-APR-143
    21.03.201431.03.2014| MARCH 21, 141
    01.04.201410.04.2014| MARCH 21, 14. 1 APRIL 142
    01.04.201410.04.2014| 1 APRIL 141

    But for the moment I did not have any starting point... Now comes the FUN part...

    When I give the State of departure; I get a single row :-(

    Example of

    SELECT a.*,
           sys_connect_by_path(start_date, '|'),
           LEVEL lvl
      FROM dates_q a
     CONNECT BY PRIOR end_date = (start_date - 1)
     START WITH start_date = To_Date('01-apr-2014','dd-mon-yyyy');
    

    The result is

    START_DATEEND_DATESYS_CONNECT_BY_PATH(START_DATE,'|')LVL
    01.04.201410.04.2014| 1 APRIL 141

    Just a line...!

    I'm unable to understand this and work more and need help.

    The formation of the tree works only in a 'sense' and I'm going the other way around? Don't know what it means but just something that comes to mind. :/

    Thank you

    K

    P.S. - database is 10g R2.

    Hello

    Thanks for the display of the data of the sample; It is very useful.

    What do you expect the result will be and why?

    LEVEL = 1 contains all rows that meet the condition to START WITH.  The rows that meet the condition

    start_date = To_Date('01-apr-2014','dd-mon-yyyy')

    in this case?  Only the line you actually obtained.

    LEVEL = N (where N > 1) contains all rows that meet the conditions regarding some FRONT CONNECT BY rank level = N - 1.  Since the only line level = 1 to end_date = To_Date('10-apr-2014','dd-mon-yyyy'), lines satisfy the condition

    End_date PRIOR = (start_date - 1).

    ? None.  End_date PREREQUISITE is April 10, while rows with start_date April 11 would fulfill this condition, there is no line on LEVEL = 2 and the query stops there.

    You would have expected this from your previous results.  The line with the start_date April 1 had no children in the previous application, so there no children in any application that has the same State of CONNECT BY.

    Maybe you meant the CONNECT BY condtion to be

    End_date = BEFORE (start_date - 1).

Maybe you are looking for