Why this query produces no output?

Why this query produces no output?
select * from
(
SELECT 40 as startvalue, (24 * 60)*(To_Date('00:40', 'HH24:MI') - To_Date('00:00', 'HH24:MI')) as c
FROM dual di
) q
where q.c = q.startvalue

And just to show that it works if round you...

SQL> ed
Wrote file afiedt.buf

  1  select * from
  2  (
  3  SELECT 40 as startvalue, round((24 * 60)*(To_Date('00:40', 'HH24:MI') - To_Date('00:00', 'HH24:MI')),0) as c
  4  FROM dual di
  5  ) q
  6* where q.c = q.startvalue
SQL> /

STARTVALUE          C
---------- ----------
        40         40

I certainly wouldn't say using TRIM as PS has suggested. TRIM is a string function, not a digital function.

Tags: Database

Similar Questions

  • Why this query can remove duplicates?

    Why this query can remove duplicates? Can someone give me detailed explanation?

    Thank you
    select salary from employees union select salary from employees;

    Hello

    See the docs.

    ' Example of the UNION
    The following statement combines the results of two queries with the UNION operator which eliminates duplicates of selected lines.
    "This statement shows that you must match the data type (using the function TO_CHAR) when the columns do not exist in one or the other table"

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/queries004.htm#i2054381

    Edit

    Here's another interpretation of your question:

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1224636375004

    Published by: hoek on October 22, 2009 17:40

  • Stupid old backpacker (me) cannot understand why this query returns 1 row

    Hi all

    In reference to {: identifier of the thread = 2456973}, why do
    select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
    , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
    from emp group by job;
    only 1 rank and not 1 for each task? In fact, I had to test it myself to believe.

    It returns the data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)
    Using only a single aggregate (count or sum) returns 1 row per job, as expected

    John Stegeman wrote:
    It returns the data as if the query were

    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
    from emp group by job)
    

    Exactly the point ;-)

    It seems that Oracle actually do, a group of 'double' in the same operation.
    Attend plans to explain in this example:

    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3  from scott.emp group by job;
    
        CLERKS  SALESMANS
    ---------- ----------
             0          0
             0          0
             0          0
             0          4
             4          0
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1697595674
    
    ---------------------------------------------------------------------------
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  HASH GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------
    

    And compare it to the one with the double aggregates:

    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3  from scott.emp group by job;
    
        CLERKS  SALESMANS
    ---------- ----------
             4          4
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 417468012
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    There are GROUP BY hash and SORT GLOBAL times.

    It is really unnecessary to an aggregate on an aggregate - if two aggregates are used "in the same group level.
    Sum() aggregates are used on an already aggregated value, so it doesn't look like Oracle which actually cures like 'first do the internal aggregate using the group specified by and then do the external aggregation on the result with any group.'

    Look at this example where I combine aggregates "double" with "single" aggregates:

    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2
      4       , count(*) COUNTS
      5  from scott.emp group by job;
    
        CLERKS  SALESMANS SALESMANS2     COUNTS
    ---------- ---------- ---------- ----------
             4          4          1          5
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 417468012
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    When you mix "doubles" and "single" aggregates, Oracle decides that unique aggregates belong to the 'outer' aggregation
    SALESMAN2 did a count on the aggregated work column which is the result of the 'internal' group by - so only 1.
    The count (*) is also the result of the aggregation of the 'internal '.

    I don't know if it's documented or if it is an 'effect' of internal code used for GROUPING SETS or the internal code used to enable the analytical functions like this:

    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3       , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2
      4       , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2
      5  from scott.emp group by job;
    
        CLERKS  SALESMANS    CLERKS2 SALESMANS2
    ---------- ---------- ---------- ----------
             0          0          4          4
             4          0          4          4
             0          0          4          4
             0          0          4          4
             0          4          4          4
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 4115955660
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  WINDOW BUFFER      |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   SORT GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    Personally, I think that I would have preferred if Oracle has raised an error on this "double aggregation" and therefore require me to write this way (if it's the result I wanted):

    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)
    

    I don't really see a good use case for aggregations of 'double'-, but rather that he could give you undetected bugs in your code, if you happen to do double aggregation without noticing.

    Interesting thing to know ;-)

  • Can't understand why this query returns multiple lines with the same data

    Hi all
    I am a relative novice and self-taught when it comes to SQL. I wrote a query to our reporting tool that returns multiple rows, and I can't understand why. I know that I can use the SELECT DISTINCT option, but it really slows the execution when I do. I'd really rather understand if I can change the code to avoid the multiples. This is the query. I've included a few statements in italics to help explain the break. Any ideas?

    SELECT MATSITE, MATPONUM, FIRSTRECPTDATE
    Of
    Subquery that concludes the first date on which purchase orders have been implemented with ACK State
    (SELECT ACKSTAT. PONUM AS 'ACKPONUM', (MIN (ACKSTAT. CHANGEDATE)) AS 'FIRSTACKDATE '.
    OF PZMAX. POSTATUS ACKSTAT
    WHERE (ACKSTAT. STATE = 'ACK') AND (ACKSTAT.ORGID ='CGSALTUS)
    GROUP OF ACKSTAT. PONUM),
    Subquery that concludes the first reception against a purchase order transaction for purposes of comparison
    (SELECT TRANS. PONUM AS "MATPONUM", TRANS. SITEID AS 'MATSITE', (MIN (TRANS. TRANSDATE)) AS 'FIRSTRECPTDATE '.
    OF PZMAX. MATRECTRANS TRANS
    WHERE (TRANS.ORGID ='CGSALTUS) AND (TRANS. HOUR > =: startDate and TRANS. TRANSDATE < =: endDate)
    TRANS GROUP. SITEID, TRANS. PONUM)
    WHERE
    (ACKPONUM = MATPONUM AND FIRSTRECPTDATE < FIRSTACKDATE) OR (NOT EXISTS (SELECT 1 FROM PZMAX. POSTATUS ACKSTAT2 WHERE (ACKSTAT2. PONUM = MATPONUM) AND (ACKSTAT2. STATE = 'ACK') AND (ACKSTAT2.ORGID ='CGSALTUS)))

    The where the instruction is intended to find when one of two conditions exists. ((1) received happened before the command either in ACK or 2) a reception that's happened, but the purchase order is never in ACK State. It seems that this second condition that creates multiple lines.

    Any thoughts will be appreciated geratly.

    Dave Teece
  • Why this query SQLLite returns the same all the time?

    Hello

    I use a search box to accept a query on three columns and am page before based on the last record, which in this case is Run Baby Run by Loopy

    I know for a fact that the database has a song inside by Loopy called Straight Down the Line, so this should at least be showing that. But it does is display the same songs again.

    Can someone explain the error in my logic here?

    SELECT * WHERE DiscID AS "loopy %" songs or artist LIKE 'loopy %' or AS "loopy %" title AND artist > = 'LOOPY' COLLATE NOCASE Title > = 'Run Baby Run' COLLATE NOCASE ORDER BY artist COLLATE NOCASE ASC, title COLLATE NOCASE ASC LIMIT 20

    Thanks for taking a peek.

    This is a forum for AS3, not SQL - etc., which may explain the slow Pickup on your ad.  While someone might offer something at some point, you should try to find a forum where they discuss SQL programming, which could mean going out of the domain of Adobe.  The closest thing I can think that would be a forum in the Adobe forums game...

    http://forums.Adobe.com/community/Dreamweaver/server_side

  • Why this query gives me wrong

    Hello

    My java file, I get the data in this format 18-11-2010 0:00:00

    So I used the query in this way

    select distinct to_char (USAGEDATE, ' yyyy-mm-dd hh: mm :) from testsummary where USAGEDATE BETWEEN 2010-10-18 0:00:00 and 18-11-2010 0:00:00)


    Help, please

    query is incorrect and needs to read

    Select distinct to_char (USAGEDATE, 'yyyy-mm-dd hh24:mi:ss')
    of testsummary
    where USAGEDATE BETWEEN to_date ("2010-10-18 0:00:00 ',' yyyy-mm-dd hh24:mi:ss'") and to_date ('18-11-2010 0:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    ----------------------
    Sybrand Bakker
    Senior Oracle DBA

  • That means 1e9 and why this query does not work?

    What does 1e9? Someone has links to documentation on this oracle? And why I get this error?
    SQL> select segment_name,(bytes/1e9) AS size from dba_segments where segment_name='MSG_MASTER';
    select segment_name,(bytes/1e9) AS size from dba_segments where segment_name='MSG_MASTER'
                                       *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected

    SIZE is a keyword - so if you want the name of the column size then use 'SIZE' else give it a different name

    Try dividing by other exponentials, then you'll see how: 1e0 1e1 (div 1), (div by 10), 1e2 :-) etc

    Mette

    Published by: mettemusens on 2009-05-12 16:02

  • Why this query does not work on the CF when it works fine on MYSQL?

    Subject says it all. I can run it through console mysql and get the result that I need, but when I place it inside a cfquery that he will not treat.

    SET @saldo = 20000;
    SELECT
    IF (Co.transtipo=0,@saldo:[email protected],@saldo:=@saldo+t.transmonto),
    @saldo: = @saldo - t.transmonto.
    t.TransID,
    t.cuentaid,
    t.operacionid,
    t.fechatrans,
    t.voucher,
    t.cheque,
    t.transtitular,
    t.transmonto,
    t.transdetalle,
    t.modificado,
    Co.transtipo,
    Co.Operacion
    OF cuentastrans t
    LEFT JOIN cuentasoperacion co ON t.operacionid = co.operacionid
    WHERE the t.cuentaid = 7
    ORDER BY t.fechatrans ASC

    Fixed, coldfusion must be labeled with 'AS' of the expressions in the opposite case he used to index the column.

  • Why between date is not return data for this query?

    Hello
    I have a table with this structure and I write this query to retrieve a few lines based on certain conditions, but this query returns no data. Can you please tell why?
    ID     DT
    
    003     11/8/2011
    002     10/8/2011
    001     9/8/2011
    And the execution of the query:
    SELECT * FROM TABLE_NAME WHERE DT BETWEEN TO_DATE('08/08/2011','dd/mm/yyyy') AND TO_DATE('12/08/2011','dd/mm/yyyy');
    Published by: starting August 13, 2011 07:10

    >

    >

    But what is the problem with that, why this date does not match when I'm providing the date format?

    What part don't you understand? You have not used TO_DATE when inserting data and default date format is dd/mm/yyyy, right? Same default date format is used if you are running:

    SELECT * FROM TABLE_NAME

    Original of your post States select returns above:

    ID     DT
    
    003     11/8/2011
    002     10/8/2011
    001     9/8/2011
    

    So the dates that you inserted are November 8, 2011, October 8, 2011-September 8, 2011. TO_DATE('08/08/2011','dd/mm/yyyy') is now August 8, 2011 and TO_DATE('12/08/2011','dd/mm/yyyy') is August 12, 2011. Then of course:

    SELECT * FROM TABLE_NAME WHERE DT BETWEEN TO_DATE('08/08/2011','dd/mm/yyyy') AND TO_DATE('12/08/2011','dd/mm/yyyy').

    will return all the lines. Bottome line - never write code that uses the implicit conversions date since your code becomes dependent on the NLS client settings and maybe working for a client and fail or produce erroneous results for other customers.

    SY.

  • Why is-isn't this query with XMLTABLE and XMLTYPE post? (xmlns)

    OK, Miss me something here - because this query returns two rows:

    Select seq_num, prdt_num
    of the double.
    XMLTable ('/ food/product ' passage)
    XmlType ("< name of food =" Test Feed"> ' |)
    ' < product id = "3000001" > < > 101 ExternalId < / ExternalId > < / product > ' |
    ' < product id = "3000002" > < > 102 ExternalId < / ExternalId > < / product > ' |
    ("< / power >")
    columns
    seq_num for the ordinalite,
    prdt_num number of path "ExternalId")
    ;

    and it does NOT work:

    Select seq_num, prdt_num
    of the double.
    XMLTable ('/ food/product ' passage)
    XmlType ("< name of food ="Test Feed"xmlns ="http://www.bazaarvoice.com/xs/PRR/SyndicationFeed/4.1"> ' |)
    ' < product id = "3000001" > < > 101 ExternalId < / ExternalId > < / product > ' |
    ' < product id = "3000002" > < > 102 ExternalId < / ExternalId > < / product > ' |
    ("< / power >")
    columns
    seq_num for the ordinalite,
    prdt_num number of path "ExternalId")
    ;

    The namespace document seems to be valid... I'm missing something obvious, I believe. But it's late, and it's Friday.

    Published by: rjbryla on June 4, 2010 15:35

    Namespaces

    When everything looks good, check your namespaces and prefixes. That you will get every day of the week.

    Derived from the post "How I declare mapping prefix to namespace with XMLTable()?" in the FAQ on this forum, your second XML would look like

    select seq_num, prdt_num
    from dual,
         xmltable(xmlnamespaces(default 'http://www.bazaarvoice.com/xs/PRR/SyndicationFeed/4.1'),
                  '/Feed/Product' passing
                  xmltype('' ||
    '101' ||
    '102' ||
    '')
                  columns
                  seq_num for ordinality,
                  prdt_num number path 'ExternalId');
    
  • Why this erroneous query works well? -Answer

    DB version: 10 gr 2
    I wanted to reproduce the non-use of rownum when used with an ORDER BY clause.
    Because ORDER BY is evaluated finally (after ROWNUMs are generated), the query below give bad result put most of the time.
    But the following query
    select ename,join_date
    from test
    where rownum<4
    order by join_date
    give me a correct result. Then, when this query will start to give erroneous results?


    alter session set nls_date_format='DD-MM-YYYY HH:MI:SS';
    
     SELECT SYSDATE FROM DUAL;
    
    SYSDATE
    -------------------
    15-12-2008 11:40:30
    
    create table test
    (ename varchar2(15),
    join_date date);
    
    
    insert into test values('JAMES',SYSDATE);
    insert into test values('CHESTER',SYSDATE);
    insert into test values('SUNITA',SYSDATE);
    insert into test values('GARRY',SYSDATE);
    insert into test values('KAREN',SYSDATE);
    insert into test values('ABDUL',SYSDATE);
    insert into test values('YING',SYSDATE);
    
    set lines 400
    select * from test;
    
    ENAME           JOIN_DATE
    --------------- -------------------
    JAMES           15-12-2008 11:41:21
    CHESTER         15-12-2008 11:41:40
    SUNITA          15-12-2008 11:41:56
    GARRY           15-12-2008 11:42:17
    TIM             15-12-2008 11:42:44
    KAREN           15-12-2008 11:52:46
    ABDUL           15-12-2008 11:53:01
    YING            15-12-2008 11:53:18
    CHAICE          15-12-2008 12:14:27
    THELMA          15-12-2008 12:14:54
    
    
    select ename,join_date
    from test
    where rownum<4
    order by join_date;
    
    ENAME           JOIN_DATE
    --------------- -------------------
    JAMES           15-12-2008 11:41:21   --correct
    CHESTER         15-12-2008 11:41:40   --correct     
    SUNITA          15-12-2008 11:41:56   --correct
    Published by: Nichols on December 15, 2008 03:37

    Published by: Nichols on December 15, 2008 03:56

    Published by: Nichols on December 15, 2008 04:09

    Run the same query, but the order of join_date DESC. You will see that the result is completely incorrect.
    The query takes just three records (not the 'top three' - there is no order) and then ordered these records based on the ORDER BY in the final predicate.

  • Sorting and grouping - two months in this query

    Hi all

    Thanks a lot for JAC

    I am doing a project for the construction company, I faced this problem by grouping points according to the relationship between these points the
    Relationship is from 1 to 100. If the point between what means there is relationship between these points has come.

    resolve this question already, but the results does not correct when the table contains more data.

    SQL - sorting and grouping.
    Jac and thanks a lot to him.

    This example for more details

    for example, I have these points
    id   location         percentage   comments 
    1     loc 1,2          20%                that mean point  1 and 2 close to each other by 20%
    2     loc 1,3          40%              that mean point 1 and 3 close to each other byy 40%
    3     Loc 8,6          25%               that mean point 8 and 6 close to each other by 25% 
    4     Loc  6,10        20%
    5     LOC 11,10        10 %
    6     LOC 15,14         0%
    In addition, we can see the relationship between these points as follows
    -points 1,2,3 in a group why because close 1.2 and 1.3 a relationship which means 1.3 also hid the relationship.
    -Points 6,8,10,11 in the second group there are the relationships between them.
    - but no relationship between 1, 2 or 3 with any point of 6,8,9,10,11
    -as well as no relationship between 15, 14, which means 14 in the third group and 15 in the fourth group.


    Whati need?

    to group the points that growing a relationship according to the percentage value


    The most important part is to group the points. For EXAMPLE, the query below, the gropuing is not correct.

    I have the following table with data
    drop table temp_value; 
    create table temp_value(id number(10),location varchar2(20), percentage number(9)); 
     
     
    insert into temp_value values  (1,'LOC 1,2',10); 
    insert into  temp_value values (2,'LOC 1,3',0); 
    insert into  temp_value values (3,'LOC 1,4',0); 
    insert into  temp_value values (4,'LOC 1,5',0); 
    insert into  temp_value values (5,'LOC 1,6',0); 
    insert into  temp_value values (6,'LOC 2,3',0); 
    insert into  temp_value  values(7,'LOC 2,4',0); 
    insert into  temp_value values (8,'LOC 2,5',30); 
    insert into  temp_value values (9,'LOC 2,6',0); 
    insert into  temp_value values (10,'LOC 3,4',0); 
    insert into  temp_value values (11,'LOC 3,5',0); 
    insert into  temp_value values (12,'LOC 4,5',40); 
    insert into  temp_value values (13,'LOC 4,6',0); 
    insert into  temp_value values (14,'LOC 6,7',40);
    insert into  temp_value values (15,'LOC 7,2',0);
    insert into  temp_value values (16,'LOC 8,2',60);
    insert into  temp_value values (17,'LOC 8,3',0);
    insert into  temp_value values (18,'LOC 3,1',0);
    insert into  temp_value values (19,'LOC 9,6',30);
    insert into  temp_value values (20,'LOC 11,2',0);
    insert into  temp_value values (22,'LOC 12,3',10);
    insert into  temp_value values (23,'LOC 19,3',0);
    insert into  temp_value values (24,'LOC 17,3',0);
    insert into  temp_value values (24,'LOC 20,3',0);
    When I used this query, the results is not correct

     with t as
        (select percentage,loc1,loc2,sum(case when percentage = 0 then 1
                           when loc1 in (l1,l2) then 0
                       when loc2 in (l1,l2) then 0
                       when l1 is null and l2 is null then 0
                       else 1
                  end) over(order by rn) sm
        from (     select id,location,percentage,
                           regexp_substr(location,'\d+',1,1) LOC1,
                          regexp_substr(location,'\d+',1,2)  LOC2,
                         lag(regexp_substr(location,'\d+',1,1))
                          over(order by percentage desc) l1,
                          lag(regexp_substr(location,'\d+',1,2))
                          over(order by percentage desc) l2,
                  row_number() over(order by percentage desc) rn
          from temp_value
          order by percentage desc
            )
      )
       select loc,min(sm)+1 grp
         from(
           select loc,rownum rn,sm
           from(
           select percentage,decode(rn,1,loc1,loc2) loc,sm
           from t a,
                (select 1 rn from dual union all
                 select 2 from dual ) b
           order by percentage desc,decode(rn,1,loc1,loc2) asc
          )
       )
        group by loc
       order by min(sm),min(rn);
    results


    SQL > /.
    LOC                         GRP
    -------------------- ----------
    2                             1
    8                             1
    6                             2
    7                             2
    4                             3
    5                             3
    9                             4
    1                             5
    12                            6
    3                             6
    11                           13
    
    LOC                         GRP
    -------------------- ----------
    19                           14
    17                           15
    20                           22
    
    14 rows selected.
    SQL >


    but the just is
    Location        group No
    2                  1
    8                  1
    4                  1
    5                  1
    1                  1
    6                  2
    7                  2
    9                  2
    12                 3
    3                  3
    19                 4
    17                 5
    20                 6
    Thanks in advance.

    Published by: Isabelle on November 30, 2012 03:07

    OK, I thought an it once again and found out how to include with any such percentage points.
    In your example expected output you missed the 11 that's why we got 7 groups now.
    The order of the Group 2 and 3 is ambiguous, because the highest percentage of these groups is the same.

    with connects as (
    select distinct
     loc1
    ,loc2
    ,connect_by_root(loc1) grp
    ,percentage per
    from
    temp_value
    --start with
    --percentage != 0
    connect by nocycle
    (prior loc2 = loc1
    or
    prior loc1 = loc2
    or
    prior loc1 = loc1
    or
    prior loc2 = loc2)
    and
    percentage != 0
    and
    prior percentage != 0
    )
    
    select
     loc
    ,dense_rank() over (order by decode(per,0,1,0), grp) grp
    from (
    select
     loc
    ,max(grp) keep (dense_rank first order by per desc, grp) grp
    ,max(per) keep (dense_rank last order by per nulls first) per
    from (
    select
     loc1 loc
    ,grp
    ,per
    from connects
    union
    select
     loc2
    ,grp
    ,per
    from connects
    )
    group by
    loc )
    order by 2,per desc,1
    
    LOC     GRP
    2     1
    8     1
    4     1
    5     1
    1     1
    12     2
    3     2
    6     3
    7     3
    9     3
    11     4
    17     5
    19     6
    20     7
    

    Think we are done now ;-)
    Edited by: chris227 at 30.11.2012 16:46

    Edited by: chris227 at 30.11.2012 17:12
    order corrected

    Edited by: chris227 at 30.11.2012 17:15
    simplification, no need to rank in linking subquery

    Edited by: chris227 at 30.11.2012 17:26

  • How can I change this query to generate a sequence

    This query
     
     select 
     SZSTCLA_PIDM, 
      SZSTCLA_TERM_CODE,
      SZSTCLA_LAST_NAME
      from SZSTCLA,SHRTGPA
     where SZSTCLA_PIDM IN ( 120125,186114)
     AND SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODE
     AND  shrtgpa_pidm  = SZSTCLA_PIDM 
      AND SZSTCLA_RECORDED_EARNED_CRED > 0 
      ORDER BY SZSTCLA_TERM_CODE
    Returns the following results
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME
    186114     198810     Johnson
    186114     198820     Johnson
    186114     198910     Johnson
    186114     198920     Johnson
    186114     199010     Johnson
    186114     199020     Johnson
    186114     199110     Johnson
    186114     199120     Johnson
    120125     200720     Smith
    120125     200810     Smith
    120125     200820     Smith
    120125     200910     Smith
    120125     200920     Smith
    120125     201010     Smith
    120125     201020     Smith
    120125     201110     Smith
    120125     201120     Smith
    Notice that ruptures in every szstcla_pidm, I need to change the query, so it can display a sequence number for each SZSTCLA_TERM_CODE
    so, it will be like
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME                                    seq 
    186114                     198810                                     Johnson                         1
    186114                     198820                                     Johnson                         2
    186114                    198910                                     Johnson                         3
    186114                    198920                                     Johnson                         4
    186114                    199010                                     Johnson                         5
    186114                    199020                                     Johnson                         6
    186114                    199110                                     Johnson                         7
    186114                    199120                                     Johnson                         8 
    then
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME                                      seq 
    
    120125                  200720                                   Smith                             1
    120125                  200810                                    Smith                             2
    120125                  200820                                   Smith                              3
    120125                  200910                                   Smith                              4
    120125                  200920                                   Smith                              5
    120125                  201010                                   Smith                              6
    120125                  201020                                   Smith                              7
    120125                  201110                                   Smith                              8
    120125                  201120                                   Smith                              9

    Looks like below, this is what you are looking for, but I can't understand why some documents are missing from the sample output

        COL1 COL2     SZSTCLT_LAST_NAME              RN
    -------- -------- ------------------------------ --
    
      120125 200920   Smith                           1
      120125 201010   Smith                           2 
    

    Maybe, if you could explain it, the query can be modified to exclude these folders as well. But, for now, downwards should suffice.

    select szstclt_pidm col1, szstclt_term_code col2, szstclt_last_name, row_number() over (partition by szstclt_pidm order by szstclt_term_code) rn
      from szstclt a
           join shrtgpt b on a.SZSTCLT_PIDM = b.SHRTGPT_PIDM and a.SZSTCLT_TERM_CODE = b.SHRTGPT_TERM_CODE
     where SZSTCLT_PIDM IN ( 120125,186114);
    
        COL1 COL2     SZSTCLT_LAST_NAME              RN
    -------- -------- ------------------------------ --
      120125 200920   Smith                           1
      120125 201010   Smith                           2
      120125 201020   Smith                           3
      120125 201110   Smith                           4
      120125 201120   Smith                           5
      186114 198810   Johnson                         1
      186114 198820   Johnson                         2
      186114 198910   Johnson                         3
      186114 198920   Johnson                         4
      186114 199010   Johnson                         5
      186114 199020   Johnson                         6
      186114 199110   Johnson                         7
      186114 199120   Johnson                         8 
    
     13 rows selected 
    
  • Why this CASE statement would not work?

    If I use a CASE in my SELECT statement and met a strange thing and just need help to understand why he did it.

    When I type this, it does not work:

    CASE TRIM (Column1)
    WHEN NULL THEN Column2
    WHEN 'foo' THEN Column2
    Of ANOTHER Column1
    END AS NewColName

    I use this query in an Oracle procedure to insert data into another table. The data inserted in the column of NewColName end up being 4 empty spaces, located in Column1. In the logic of this, TRIM must remove all the empty spaces, and he should get mapped to the first statement WHEN, who must insert the value of Column2, but that does not occur. I tried the following versions of the first line as well:

    LTRIM (RTRIM (Column1)) CASE
    CASE of REPLACE (Column1, ' ', ")

    and they all produce the same result. I also tried to change WHEN NULL for WHEN " and it changed nothing. However, when I rewrite the statement in this way it works the way it should:

    CASE
    WHEN TRIM (Column1) IS NULL, Column2
    WHEN TRIM (Column1) = 'foo' THEN Column2
    Of ANOTHER Column1
    END AS NewColName

    In my mind, it seems that these two methods are trying the same thing, why we could work and the other not? Only, it has no sense to me.

    Thank you

    Hello

    Welcome to the forum.

    In your first statement, you have

    WHEN NULL THEN.

    This is the same as x = NULL.

    Nothing is never equal to NULL, if you find yourself in your ELSE clause.

    Concerning
    Peter

  • How to write this query in the hierarchy

    Hi gurus,

    Really need your help on this query.  Thank you very much in advance.

    SELECT
      t1.key as root_key ,
    (SELECT
          t2.unit_id AS unit_id 
          level-1 AS level ,
          t2.name,
          t2.creator
        FROM
          tab t2
          START WITH t2.unit_id       =   t1.unit_id            -----check each node as root
          CONNECT BY prior t2.unit_id = t2.parent_unit_id
    
      )
       t1.name as parent_unit_name
    FROM
      tab t1
    

    I'll write a query of the hierarchy as above, and that EACH line (node, totally more than 10200) is checked as root node to see how many sheets are accessible for her... It must be implemented in a single query.

    I know inline query should NOT return multiple rows or multiple columns, but the inline elements are necessary and can certainly be made in a correct solution.

    (env):

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    PL/SQL Release 12.1.0.2.0

    )

    Test data:

    select 1 as unit_id, null as parent_organization_unit_id, 'U1' as name from dual
    union all
    select 2, 1, 'U2' FROM DUAL
    UNION ALL
    SELECT 3, NULL, 'U3' FROM DUAL
    UNION ALL
    SELECT 4, 3, 'U4' FROM DUAL
    UNION ALL
    SELECT 5, 2, 'U5' FROM DUAL
    UNION ALL
    SELECT 6, 5, 'U6' FROM DUAL
    UNION ALL
    SELECT 7, 6, 'U7' FROM DUAL
    UNION ALL
    SELECT 8, 5, 'U8' FROM DUAL
    UNION ALL
    SELECT 9, 5, 'U9' FROM DUAL;
    

    Final result should be like this

    key unit_id,    level,   name, parent_name
    1    1    0    u1      u1
    1    2    1    u2       u1
    1    5    2     u5      u1
    1    6    3     u6      u1
    1    7    4    u7       u1
    1    8    3    u8       u1
    1    9    3     u9      u1
    2    2    0     u2       u2
    2    5    1      u5       u2
    2    6    2     u6       u2
    2    7    3      u7      u2
    2    8    2      u8       u2
    2    9    2      u9       u2
    
    

    Don't know how get you your output, it does not match your data...

    with tab as)

    Select 1 as unit_id, null as parent_organization_unit_id 'U1' as the name of double

    Union of all the

    Select 2, 1, 'U2' FROM DUAL

    UNION ALL

    SELECT 3, NULL, 'U3' FROM DUAL

    UNION ALL

    SELECT 4, 3, 'U4' FROM DUAL

    UNION ALL

    SELECT 5, 2, 'U5' OF THE DOUBLE

    UNION ALL

    SELECT 6, 5, 'U6' OF THE DOUBLE

    UNION ALL

    SELECT 7, 6, "U7" OF THE DOUBLE

    UNION ALL

    SELECT 8, 5, 'U8' FROM DUAL

    UNION ALL

    9. SELECT, 5, 'U9' FROM DUAL

    )

    Select dense_rank() key (order by connect_by_root unit_id), unit_id, level - 1 as 'LEVEL', connect_by_root name root_parent_name

    t tab

    Start with parent_organization_unit_id is null

    Connect prior unit_id = parent_organization_unit_id

    KEY UNIT_ID LEVEL ROOT_PARENT_NAME
    1 1 0 "U1".
    1 2 1 "U1".
    1 5 2 "U1".
    1 6 3 "U1".
    1 7 4 "U1".
    1 8 3 "U1".
    1 9 3 "U1".
    2 3 0 "U3".
    2 4 1 "U3".

Maybe you are looking for

  • Constant crashing Skype on win 10

    If Skype has been giving me two questions. The first is it hangs often enough, for what seems like no reason. I've included a dxdiag. The second is that in the group conversation, that I am, my messages are suspended. They sit and stay forever and so

  • Pavilion 17-g121wm: laptop refurbished with no Windows license key

    Greetings, I just got a used Pavilion laptop. It came with 10 windows pre-loaded and is in perfect working condition, but they stripped all the stickers from him, including one with the Windows license key. If I buy the HP recovery media, it will hav

  • Handyman do not move at right angles

    I have Vista Ultimate and just downloaded and installed Tinker. The arrows do not move the robot out of the place but to be going in a circle in the same cell. Is - fixable?

  • update security for windows 9 64 bit, not able to be updated, configured components incrrectly

    The place where windows update stores has changed and needs to be repaired? According to the microsoft fix - it Center

  • ISE rebuild - Cert Question

    Had to rebuild our ISE primary and secondary (HA) devices because of the hardware failure. Currently, I have improved the capacity of the disk with disks mirrored with HSP. In the reconstruction, I was unable to use my backup. So my question is: if I