How to query this result?

with main as (

Select '-1' kisi, '10' thread from dual

Select '-1', '20' from dual

Select '-1', '30' from dual

Select '5', '40' from dual

Select '-1', '50' from dual

Select '-1', '60' from dual

Select '4', '70' from dual

Select '4', '80' from dual

Select '-1', '90' from dual

Select '-1', '99' from dual order by 2)

Select Kisi , thread from main order by thread;

Result must be




   

Kisi
min_threadmax_thread-1103054040-1506047080-19099

If you do not have a sort column:

with the hand in the form)

Select kisi '-1', '10' double thread.

Union all select '-1 ', ' 20' double '.

Union all select '-1 ', ' 30' double '.

Union all select '5', '40' double

Union all select '-1 ', ' 50' double '.

Union all select '-1 ', ' 60' double '.

Union select all '4', '70' from dual

Union select all '4', '80' of the double

Union select all '-1 ', ' 90' the double '.

Union select all "(-1 ', ' 99' double ordering by 2).

Select kisi, min (thread), max (thread) in)

Select sum (flag) on grp wire, kisi, (drive by wire)

de)

Select decode (kisi, lag (kisi) over (order by wire), 0, 1) flag

kisi

wire

of the hand

)

)

Grp group, kisi;

Tags: Database

Similar Questions

  • How to query this performance internally

    Dear all,

    This query selects the nth highest paid employee details, we can achieve this by rank or desnse_rank functions also
    But these execution is easily understandable. But not able to understand how this below a correlated subquery Iam running in-house. Please help me on this query
    Select * from emp where & n = (select count (distinnct b.sal) of emp b where a.sal < = b.sal)

    Thanks in advance

    Hello

    To facilitate understanding, I prefer it written this way:

    select * from emp a where (select count(distinct b.sal) from emp b where a.sal<=b.sal) = &n ;
    

    It means then:
    Select the lines of the emp table for which the number of distinct lower wages is n.
    In other words => for each lines of the PGE, it counts the number of distinct treatments that are below the current line; If the number is & n, the current emp lines is displayed

  • How to get this result

    I have data like this

    create temp table abc (whole userid, clo_id, timestamp c_date, whole ilo_id integer, i_date timestamp)

    insert into abc values (1.11, January 5, 2009 ", 211, January 2, 2009 '");
    insert into abc values (' 1.11, January 5, 2009 ", 212, January 3, 2009 ');
    insert into abc values (1.11, January 5, 2009 ', 213, January 4, 2009 ');

    UserID Clo_id c_date ilo_id i_date
    1 11 1/5/2009 0:00 213 1/4/2009 0:00
    1 11 1/5/2009 0:00 212 1/3/2009 0:00
    1 11 1/5/2009 0:00 211 1/2/2009 0:00


    Suppose now that if I set the frequency 2, the I need to get an output shows

    UserID Clo_id c_date ilo_id i_date frequency
    1 11 1/5/2009 0:00 213 1/4/2009 0:00 1
    1 11 1/5/2009 0:00 212 1/3/2009 0:00 2
    1 11 1/5/2009 0:00 211 1/2/2009 0:00 1

    Do you mean like this?

    with abc as (select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 216 ilo_id, to_date('06/01/2009', 'dd/mm/yyyy') i_date from dual union all
                 select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 215 ilo_id, to_date('05/01/2009', 'dd/mm/yyyy') i_date from dual union all
                 select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 214 ilo_id, to_date('04/01/2009', 'dd/mm/yyyy') i_date from dual union all
                 select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 213 ilo_id, to_date('04/01/2009', 'dd/mm/yyyy') i_date from dual union all
                 select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 212 ilo_id, to_date('03/01/2009', 'dd/mm/yyyy') i_date from dual union all
                 select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 211 ilo_id, to_date('02/01/2009', 'dd/mm/yyyy') i_date from dual),
    -- end of mimicking data in a table called abc
     results as (select userid,
                        clo_id,
                        c_date,
                        ilo_id,
                        i_date,
                        floor((i_date - min(i_date) over (partition by userid, clo_id))/2) dt_grp
                 from   abc)
    select userid,
           clo_id,
           c_date,
           ilo_id,
           i_date,
           row_number() over (partition by userid, clo_id, dt_grp order by i_date, ilo_id) frequency
    from   results
    order by userid, clo_id, i_date desc, ilo_id desc;
    
        USERID     CLO_ID C_DATE                  ILO_ID I_DATE               FREQUENCY
    ---------- ---------- ------------------- ---------- ------------------- ----------
             1         11 05/01/2009 00:00:00        216 06/01/2009 00:00:00          1
             1         11 05/01/2009 00:00:00        215 05/01/2009 00:00:00          3
             1         11 05/01/2009 00:00:00        214 04/01/2009 00:00:00          2
             1         11 05/01/2009 00:00:00        213 04/01/2009 00:00:00          1
             1         11 05/01/2009 00:00:00        212 03/01/2009 00:00:00          2
             1         11 05/01/2009 00:00:00        211 02/01/2009 00:00:00          1
    

    ETA: If you want to change the frequency of days, then you would change the number of division in this line:

                        floor((i_date - min(i_date) over (partition by userid, clo_id))/2) dt_grp
    

    for example. If you wanted every 3 days, you change the 2 to 3.

    Published by: Boneist on 23-Sep-2010 15:12

  • How to transform this PL/SQL query in a PL/SQL function?

    Salvation of nice people!

    I have a nice flash chart that SQL code is below. I want to see this table only if this query returns results. I tried to put it in condition. How transformt this ciode SQL "SLQ function returning a Boolean"?
    DECLARE
    X VARCHAR2 (4000);
    BEGIN
    x := 
    'SELECT NULL LINK, trunc(a.DATE1, '''||:P13_TRUNC||'''), avg(b.pourcentage_remplissage)
    FROM    EVV_'||:P13_SITE||' a, bassin_remplissage b
    WHERE   a.CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE='''||:P13_SITE||''') 
    AND     round(a.valeur, 1) = b.cote_ngf
    AND     DATE1 BETWEEN 
    TO_DATE ('''||:P13_DATE_DEBUT||'000000'', ''DD/MM/YYYYHH24MISS'') AND 
    TO_DATE ('''||:P13_DATE_FIN||'235959'', ''DD/MM/YYYYHH24MISS'') 
    group by trunc(a.DATE1, '''||:P13_TRUNC||''')
    ORDER BY trunc(a.DATE1, '''||:P13_TRUNC||''')';
    RETURN (X);
    END;
    Thank you for your kind replies.

    Christian

    Christian:

    Try this

    DECLARE
       x   VARCHAR2 (4000);
    BEGIN
       x :=
             'SELECT COUNT(*)
    FROM    EVV_'
          || NVL(:p13_site, 'E003')
          || ' a, bassin_remplissage b
    WHERE   a.CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE='''
          || NVL(:p13_site, 'E003')
          || ''')
    AND     round(a.valeur, 1) = b.cote_ngf
    AND     DATE1 BETWEEN
    TO_DATE ('''
          || NVL(:p13_date_debut, '01/01/1980')
          || '000000'', ''DD/MM/YYYYHH24MISS'') AND
    TO_DATE ('''
          || NVL(:p13_date_fin, '01/01/2080')
          || '235959'', ''DD/MM/YYYYHH24MISS'')
     ';
    
       EXECUTE IMMEDIATE x
       INTO WWV_FLOW.g_id;
    
       IF wwv_flow.g_id IS NULL OR wwv_flow.g_id = 0
       THEN
          RETURN FALSE;
       ELSE
          RETURN TRUE;
       END IF;
    END;
    

    Published by: city has 8 July 2009 06:12
    Moved the 'back' clause where it should be :)

    Published by: city has 8 July 2009 06:13

  • I save by mistake several times my C drive to the D drive and this resulted in my D drive is almost full with backups of 150 GB. How can I delete the backups of my D drive?

    I make mistake and have backed up all my C drive on my D drive contains and this resulted in my D drive is almost full with backups of 150 GB drive C. How can I clean all my backups of my D drive?

    Hi, Mr. flame.

    What is your operating system?

    If you have been creating full backups, the backup only that you keep is the last.

    Data backup file: offers the possibility to delete backups of data on the target files to free up space.

    Backup disk space management

    http://blogs.technet.com/b/filecab/archive/2009/11/23/managing-backup-disk-space.aspx

    You can also delete them using disk cleanup

    http://Windows.Microsoft.com/en-us/Windows7/delete-files-using-disk-cleanup

  • Don't know how to read the results of netstat EI s list? If I received 860592506 bytes sent from 43421482 how to convert MB? And does this mean byte received?

    Don't know how to read the results of netstat EI s list? If I received 860592506 bytes sent from 43421482 how to convert MB? And does this mean byte received?

    Hello

    This shows the total number of bytes transmitted and received via the Ethernet card. This is the total of the amount of use up to this day.

    This includes all the Web sites you have visited and emails you sent, etc..

    You can calculate using one of the following methods:

    Method 1:

    860592506 / 1048576 = 820,72 MB

    Method 2:

    Multiply 860592506 with 9.53674316 * 10 ^-7 that will give us the result in mega bytes.

    860592506 bytes = 820 MB 9MB not, accept my apology for the miscalculation.
    Similarly 43421482 acroos = 40MB

  • No idea how to write this query

    Hi, My Data is as below

    DocNum doc_date type of amount
    1154 15 November 11 232501.5 invoice
    200206 4 November 11 - 243672.64 credit memo
    Note flow 111 5 November 555.22 11

    Output must be

    DocNum doc_date amount Type AmountDR AmountCR
    1154 232501.5 15 November 11 Bill 232501.5
    Note credit 200206 4 November 11 - 243672.64 - 243672.64
    Note flow 111 5 November 555.22 11 555.22

    If the amount is > 0, then it must be displayed in the value of the amount to be AmountDR
    If amount < 0 then it must be displayed in the value of the sum amount CR



    Can help how to write this query
    with sample_table as (
                          select 1154 Docnum,date '2011-11-15' doc_date,232501.5 Amount,'Invoice' type from dual union all
                          select 200206,date '2011-11-04',-243672.64,'Credit Memo' from dual union all
                          select 111,date '2011-11-05',555.22,'Debit Memo' from dual
                         )
    select  Docnum,
            doc_date,
            Amount,
            type,
            case
              when Amount >= 0 then Amount
            end AmountDR,
            case
              when Amount < 0 then Amount
            end AmountCR
      from  sample_table
    /
    
        DOCNUM DOC_DATE      AMOUNT TYPE          AMOUNTDR   AMOUNTCR
    ---------- --------- ---------- ----------- ---------- ----------
          1154 15-NOV-11   232501.5 Invoice       232501.5
        200206 04-NOV-11 -243672.64 Credit Memo            -243672.64
           111 05-NOV-11     555.22 Debit Memo      555.22
    
    SQL> 
    

    SY.

  • How to do this? 2 querys results

    Hi all

    I'm stuck with the following problem.
    I need to get all the information of two querys / tables and show them in a single table.
    I guess I need to do this in a loop, more or less, I can't do a query in a query.
    That's what I have, but does not work as it still shows the same name.

    < name cfquery = "getAccounts" datasource = "#db2use #" >
    SELECT *.
    BANNER
    < / cfquery >

    < cfoutput query = "getAccounts" >
    < cfset advertPID = #advertPID # >
    < / cfoutput >

    < cfquery name = "ListUsers" datasource = "#db2use #" >
    SELECT *.
    To useraccount
    WHERE PIDID = ' #advertPID #
    < / cfquery >

    < cfoutput query = "ListUsers" >
    < cfset UserAccount = #name # >
    < / cfoutput >

    < cfoutput query = "getAccounts" >
    name: #name # | advertPID: #advertPID # < br / >
    < / cfoutput >

    Both ListUsers and getAccounts have a lot of data.

    Someone here who can show me how to do this?
    Thank you.

    -something like this-


    SELECT u.name, b.advertPID
    U useraccount
    INNER JOIN banners b ON u.PIDID = b.advertPID


    name: #name # | advertPID: #advertPID #.

    - or -


    SELECT u.name, b.advertPID
    U useraccount, banner b
    WHERE u.PIDID = b.advertPID


    name: #name # | advertPID: #advertPID #.

    Phil

  • How ot do this query

    some of you that it won't be easy, but for a rookie plsql is not form. Can U help?

    want to find out who has max (salary) and record that information in a variable

    Table: used
    id  salary
    1    2000
    2    2500
    3    1800
    Select max (salary) in employee == > back 2500
    But how to write this in a plsql and find the id is 3 and save it in a variable


    my incomplete statement:

    Select max (salary), in myvar to employee where id =?

    can you help me?

    Oh and save it in a variable plsql:

    declare my_var emp.empno%TYPE;
    begin
      select e1.empno into my_var
      from emp e1
      where e1.sal = (select max(e2.sal) from emp e2)
        and rownum = 1;
    end;
    /
    
  • Error, please help me, how to handle this?

    Please help me, how to handle this? 2892 ArgumentException: the parameter: System.Net.Sockets.OverlappedAsyncResult is not valid. Use the object returned by the corresponding asynchronous Begin call. Parameter name: asyncResult: at System.Net.Security._SslStream.EndRead (IAsyncResult asyncResult) at?. (IAsyncResult) at System.Net.LazyAsyncResult.Complete (IntPtr userToken) at System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state) to the System.Net.ContextAwareResult.Complete (IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback (object result, IntPtr userToken) at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback (errorCode, UInt32, UInt32 numBytes, nativeOverlapped NativeOverlapped *) to System.Threading._IOCompletionCallback.PerformIOCompletionCallback (errorCode, UInt32, UInt32 numBytes, NativeOverlapped * pOVERLAP)

    It's not a usual mistake. Despite this, try this link to error.

    https://social.technet.Microsoft.com/search/en-us?query=NET.Sockets%20based.%20overlapped&AC=4#refinementChanges=&PageNumber=1&showMore=false

    Details of youre also treat, try .net cmd, opening type: netsh Winsock reset exit, restart the pc

  • When I'm on a video call with somone that my photo is still backwards down.how I fix this?

    When I'm on a video call with someone, that my photo is still backwards down.how I fix this?

    Hi Carolannjansson,

    Thanks for posting your query in Microsoft Community.

    I imagine the inconvenience that you are experiencing and will certainly help you in the right direction to solve the problem. However, I would be grateful if you could answer a few questions to refine the question in order to provide you with better assistance.

    1. What application you use to make a video call?
    2. Are all the device drivers and Windows updates are updated?
    3. What is the brand and model of your computer?
    4. It was working fine? If Yes, did you significant changes before the show?

    If you use Skype you can check the following thread and see if it helps you to solve the problem.

    The webcam image is upside down Skype.

    Get back to us with all the necessary information and the result of the proposed suggestion. We will be happy to help you.

    Kind regards

  • How to query a hierarchical structure (Director and employee)

    Hi all
    I use the Oracle 10 g R2 database.
    Suppose I have this structure
    EMP_ID               EMP_NAME          MANAGER_ID
    1                    KING               
    2                    STEVE               1
    3                    FRANK               2
    What I want, that is when I get any EMP_ID, I want to get all the Manager of his first and the last record is the employee in the leaf of the hierarchy in the query.

    For example, when I ask EMP_ID = 2, I want to get this result
    EMP_ID               EMP_NAME          MANAGER_ID
    1                    KING               
    2                    STEVE               1
    and when I search EMP_ID = 3, I want to get this result:
    EMP_ID               EMP_NAME          MANAGER_ID
    1                    KING               
    2                    STEVE               1
    3                    FRANK               2
    How to write this query?
    with xx as
    (
    select 1 eid, 'KING' emp_name, NULL mid from dual UNION ALL
    select 2 eid, 'STEVE' emp_name, 1 mid from dual UNION ALL
    select 3 eid, 'FRANK' emp_name, 2 mid from dual
    )
    select *
            from xx
        start with eid = 2
        connect by eid = PRIOR mid
    order by eid;
    

    Output:

    1     KING
    2     STEVE     1
    

    With emp_id = 3

    with xx as
    (
    select 1 eid, 'KING' emp_name, NULL mid from dual UNION ALL
    select 2 eid, 'STEVE' emp_name, 1 mid from dual UNION ALL
    select 3 eid, 'FRANK' emp_name, 2 mid from dual
    )
    select *
            from xx
        start with eid = 3
        connect by eid = PRIOR mid
    order by eid;
    

    Output:

    1     KING
    2     STEVE     1
    3     FRANK     2
    
  • Some Basic steps how to grant this request

    Hi all

    It's my cursor from query to extract the eligible orders its takes too long to execute, it is my request

    Oeol.header_id, oeol.attribute1, oeoh.order_number, COUNT (1) SELECT consignment_count
    Of oe_order_lines_all oeol, oe_order_headers_all oeoh, oe_transaction_types_all oett
    WHERE oeol.header_id = oeoh.header_id
    AND oeol.flow_status_code IN (DECODE (oett.name, xxhdnl_om_common_util_pkg.g_push_line_type,
    DECODE (oeol.shipment_priority_code, 'EXPRESS', DECODE (oeol.flow_status_code, 'AWAITING_STOCK'

    'AWAITING_STOCK', 'STOCK_RECEIVED', 'STOCK_RECEIVED'), 'STOCK_RECEIVED')

    DECODE (XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull (oeol.line_id), 'PUSH', 'BOOKED')))

    AND (oeol.shipment_priority_code = p_shipment_priority OR p_shipment_priority IS NULL)

    AND oeol.line_type_id = oett.transaction_type_id AND oett.name IN
    (xxhdnl_om_common_util_pkg.g_return_line_type
    xxhdnl_om_common_util_pkg.g_push_line_type)
    AND oeoh.attribute3 IS NULL
    GROUP BY
    oeol.header_id
    oeol.attribute1
    oeoh.order_number;



    Thanks for giving some basic steps for the update about some performance.


    Thanks and greetings

    Srikkanth.M

    The code seems not very readable. Poor guy if you have to maintain that.
    I like this part:

    .. oeol.flow_status_code IN (DECODE (oett.name, xxhdnl_om_common_util_pkg.g_push_line_type,
    DECODE (oeol.shipment_priority_code, 'EXPRESS', DECODE (oeol.flow_status_code, 'AWAITING_STOCK'
    'AWAITING_STOCK', 'STOCK_RECEIVED', 'STOCK_RECEIVED'), 'STOCK_RECEIVED')
    DECODE (XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull (oeol.line_id), 'PUSH', 'BOOKED')))

    you combine global variables of PL/SQL with a 3 decodes nested, I'd go for CASE and some formatting.

    But what makes this so slow query, it's, I guess:

    XXHDNL_OM_QUI_BAT_PLAN_EXT_PKG.check_push_or_pull (oeol.line_id)

    for each row returned by (part of) query. What does this package? Run additional queries with oeol.line_id as a parameter?
    According to the way that ORACLE creates the execution plan, this package can run before or after the other filters have been applied. This result in how Subselects in the worst case?
    Very risky. Try to make this logic in the query itself, the CASE statement is very powerful.

    -andy

  • I can't play video of videomega.tv on mozilla, but when I use chrome, it works. How to solve this problem? Thank you...

    I can't play video of videomega.tv on mozilla, but when I use chrome, it works. On mozilla that it still can not be charged, said just because the server or network failed, or may format not supported. I have already updated to flash player and use html5 extension, without result. How to solve this problem? Thank you...

    Thank you for your advice, but when I checked it on topic: config, the value is 2, so I don't change anything.

    When I search another solution, accidentally, I installed engine (socialmedia.com) unwanted search so I am forced to reset mozilla. After that, the two problem solved all of a sudden!

    Thanks for all your help and advice, it is very appreciated by me.

  • I can not find how to run this program on my HP50g Bessel functions...

    Hello!

    Recently, I buy my HP50g calculator and tried to find and install programs that I need... Solvesys is running, but I can't find how to operate this Bessel function program. I installed it exactly as solvesys (load the lib archive on the calculator and chargue on flash), but I can't find how to run commands, or when they are to crush with. I tried to access the list of orders directly through flash (press the arrow to the right while on archive of lib, then select from the list an eval push) but I get only a result bad argument...

    Can someone guive me a helping hand?

    The link for the program is

    http://www.HPCalc.org/details.php?id=3140

    Thanks in advance for your help

    Hi!, Ahkran:

    Happy new year and welcome to the Forum!

    (1) you need to download the library library 764, BESSEL V1.2, HP50G, in the HOME directory.

    Now, you need to install and stay permanently in memory, in any port (0, 1 or 2). Best if the option port 2 (Flash)...

    Now, reset the HP50G, with YOU and key F3 (C)...

    Find the library in Port 2, with orange right shift key and key LIB (2), with name BESSE. If necessary, use the NXT (L) key...

    Now press the function key (F1... F6), just below the word BESSE, in your HP50G.

    You have to see...

    and with NXT - key...

    Carefully read the instructions for use library 764, the .pdf file, the author.

Maybe you are looking for