Need help with query Cumulative difference

Hi all

I need help with a query and my requirement is as below

{code}

ROWNOORDERSVALUE

110900
211700
312500
413400

{/ code}

I have need to query which will display the cumulative difference for example I value tell 10000 numbers opening

now I need for each of the lines of cumulative difference

{code}

ROWNO ORDERS DIFF

1 10 10000 - 900 = 9100

2 11 9100 - 700 = 8400

3 12 8400 - 500 = 7900

4 13 7900 - 400 = 7500

{/ code}

WITH commands LIKE (10 SELECT order_id, 900 double UNION ALL val
11. SELECT, 700 FROM dual UNION ALL
SELECT 12, 500 FROM dual UNION ALL
Select 13, 400 double)

SELECT row_number() over (ORDER BY order_id ASC) AS rowno
order_id
sum (val) 10000 - OVER (ORDER BY order_id ASC) AS diff
orders

/

HTH

Tags: Database

Similar Questions

  • Need help with query SQL Inline views + Group

    Hello gurus,

    I would really appreciate your time and effort on this application. I have the following data set.

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
    1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19

    Please ignore '-' added for clarity

    I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.

    The query should return the following data set

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
    Here's my query. I'm a little lost.

    Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    de)
    Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
    of the INVOICE
    Sequence_id group check_date, check_number, invoice_number, vendor_number
    ) A, B OF INVOICE
    where A.sequence_id = B.sequence_id


    Thank you
    Nick

    It seems that this is a duplicate thread - correct me if I am wrong in this case->

    Need help with query SQL Inline views + Group

    Kind regards.

    LOULOU.

  • Need help with query between 2 dates

    Hello

    I did not SEE in a long time and need help with a simple query.

    I have a table of DB access with 3 fields, name, date and number

    What I want is to create a query to retrieve all the names between 2 dates

    When I ask the date field, the results are showing in this formats 2013-07-12 00:00:00

    Here's my query

    < cfquery datasource = 'mydb' name = 'test' >

    SELECT name from myTable

    where edate between ' 2011-01-01 00:00:00 ' AND ' 2013-01-01 00:00:00 '

    < / cfquery >

    < cfoutput query = 'test' >

    #name #.

    < / cfoutput >

    What I get is this error

    ODBC = 22005 (assignment error) error code

    [Microsoft] [ODBC Microsoft Access driver] Type mismatch of data in the expression of the criteria.

    Don't know what I'm doing wrong here.

    Please let me know.

    Thank you

    SELECT ename

    FROM MyTable

    WHERE edate BETWEEN

    AND

    #ename #.

  • need help with query can find data back please help.

    Hi guys I have a table such as
    CREATE TABLE "FGL"
      (
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )
    and I have a data as such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');
    I need bascially to get the total of the budget column. However this is not as simple as it sounds good (at least not for the me.) totals carried forward to the new period. you will notice that you have a period column. Basically, what im is that
    fgl_grant_year 10 1 period = account 7600 its $100 and $100 for the period 2, you see $ 100 more, it wants to not be added to this is the door on the balance. that is $100.
    So im trying to write a query that basically does the following.
    IM considering a period for the sake of this example let period 1 I get anything else. I find that the greates contributes dumpster year the amount for the period 14 (which corresponds to the total of the previous year) and add it to the amount of the current year. in this case period 1 grnt_year 11
    the expected result is therefore $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400
    do not forget that I am not given a just a period of the year.
    any help you guys can give would be immensely appreciated. I tried to get this to work for more than 3 days now.
    Finally broke down and put together this post

    Published by: mlov83 on Sep 14, 2011 20:48

    Hello

    Thanks for posting the CREATE TABLE and INSERT statemnts; It is very useful.

    I'm not sure that understand your needs.
    The correct output will be just one line:

    TOTAL_BUDGET
    ------------
             700
    

    or will it be 3 ranks that you posted? I guess you want just line after line.

    Do you mean that you are given a period (for example, 1).
    First you have to find the largest gfl_grnt_year which is related to this period (in this case, 11).
    Then you need to add fgl_budget lines that have to be
    (1) the specific period and the largest fgl_grnt_year, or
    (2) perriod = 14 and the previous fgl_grnt_year (in this case, 10).
    Is this fair?

    If so, here's a way to do it:

    WITH     got_greatest_year     AS
    (
         SELECT     fgl.*     -- or whatever columns are needed
         ,     MAX ( CASE
                     WHEN  fgl_period = :given_period
                     THEN  fgl_grnt_year
                    END
                  ) OVER ()     AS greatest_year
         FROM     fgl
    )
    SELECT     SUM (fgl_budget)     AS total_budget     -- or SELECT *
    FROM     got_greatest_year
    WHERE     (     fgl_grnt_year     = greatest_year
         AND     fgl_period     = :given_period
         )
    OR     (     fgl_grnt_year     = greatest_year - 1
         AND     fgl_period     = 14
         )
    ;
    

    If you want the 3 lines you have posted, then change the main SELECT clause to ' SELECT * ' (or, instead of *, youcan the columns you want to see the list).

  • Need help with query of queries

    I have the query 'almost' out there, but I don't know exactly how to proceed.

    I need all of the recrods meets the criteria of the query AppliedLicense.

    But not all records will have a match in the ApprovedLicense query.

    In the MergedData query I hope to have the column with date_exp filled with ApprovedLicense data when there is a football match but NULL if there is not a match.

    The code below, of course, only returns records where there is a match in the two data sources, but I have no idea how to proceed.

    Thanks for any help.

    You could do it yourself with functions of list if I hope, you do not have too many files. After executing the second query:


    You have now 2 lists of coordinates

    Subsequently during the processing of the first query,





  • Need help with query for points and polygons, 2 tables of

    Hi all

    I'm slowly stumbling along trying to figure things out space.

    I have two tables, GEO_POINTS:
    (
    DEP_ID NUMBER (12) NOT NULL,
    LINE NUMBER 4 NOT NULL,.
    MDSYS. POINT_LOC SDO_GEOMETRY
    )

    and POLYGON_AREAS:
    (
    POLY_NAME VARCHAR2 (120 CHAR),
    POLY_DESC VARCHAR2 (120 CHAR),
    MDSYS POLY_POINTS. SDO_GEOMETRY
    )

    Neither table is engraved in stone, if any, I can change some structure.

    I'm trying to understand how to write a query to retrieve all the points in a polygon, perhaps even with an optional buffer provided by the user.

    Conversely, I would probably also need to know what polygons a point would have drawn in, and it's the only request I could make any progress on.

    What I have so far, which is not working properly, is the following:

    Select * from deposits_search where dep_id in)
    SELECT dep_id
    OF geo_points, polygon_areas
    where (sdo_relate)
    poly_points,
    (SELECT point_loc
    OF geo_points
    WHERE dep_id = 10282444),
    ("mask = ANYINTERACT") = "TRUE");

    In the light of the foregoing, I want to select all the lines of a third table (DEPOSITS_SEARCH), for all polygons which is a point. The DEP_ID column is my primary key for most of the data tables in the database, and the number rose in my application query. However, the above returns all rows. It should only return one, because I only have a polygon of test defined so far.

    Any help is greatly appreciated. Thank you

    Bill Ferguson

    in which case you must include a line of buffer for the interaction between the points and polygons (with a stamp),

    better, you use the SDO_WITHIN_DISTANCE operator.

    http://download.Oracle.com/docs/HTML/B14255_01/sdo_operat.htm#i77653

    Not so sure what you mean with "I always have problems while providing a point location and extract the polygons that point would be plotted in" as so-called before unless you want that as a 'transitional instance of a geometry. (Specified using a variable binding or a builder SDO_GEOMETRY.) »

    http://download.Oracle.com/docs/HTML/B14255_01/sdo_operat.htm#i78531

    Read what geometry2 means in there. Read the examples and you will see that you have the geometry second in space operator as a builder. If this is what you need.

    Luke

  • Need help with query

    Have the rank as below,

    name of the sum

    100 A1

    -A2 200

    A3 300

    50 A1

    -A2 700

    A3 80

    10 A1

    -A2 90

    30 A3

    Need to query to extract the output like this:

    B1                     B2

    A1 + a3 (Sum) A2 (sum)

    Please help me out of this...

    Hello

    It is difficult to understand what you want... A guess based on many assumptions:

    -B1 and B2 are column headers,
    -"A1 + A3" and "A2" in the 'exit' is simply to indicate that you want the sum of the amounts for the first names.

    -Some of the AI have all their amounts > = 0, others have their amounts<=>
    -You want to make the sum of all positive numbers in the first column and all the negatives in the second column

    SELECT SUM (GREATEST (0, t.amount)) b1

    , B2 SUM (LESS (0, t.amount))

    MYTABLE t

    ;

    (I think there is only a bit of luck it's really what you want, but provide a full test case and the output that you really want and why not, try to explain / explicit rules, then we can give better help)

    Best regards

    Bruno Vroman.

  • need help with query-please help

    Hi all
    I want to convert the query to a view online below. I write examples of data that I used
    create table pde(empno number(10),act_hour varchar(10 byte));
     
    Table created
     
    insert into pde values(211,'12:20');
    insert into pde values(211,'06:00');
    insert into pde values(213,'07:00');
    insert into pde values(213,'07:20');
     
    WITH  got_total_hours     AS
    (
         SELECT SUM (   TO_NUMBER (SUBSTR (act_hour, 1, 2))
                    + ( TO_NUMBER (SUBSTR (act_hour, 4, 2))
                      / 60
                      )
                    ) AS total_hours  
         from      pde
     
    )
    SELECT        TO_CHAR (FLOOR (total_hours))
           || ':'
           || TO_CHAR ( MOD (total_hours, 1) * 60
                  , 'fm00'
                   )     AS hh_mm,empno,act_hour
    FROM     got_total_hours ,pde
     
    this is the output i am getting  
     
    HH_MM  EMPNO  ACT_HOUR
    32:40     211     12:20
    32:40     211     06:00
    32:40     213     07:00
    32:40     213     07:20
    
    i tried changing the above query to an inline view given below
    SELECT        TO_CHAR (FLOOR (total_hours))
           || ':'
           || TO_CHAR ( MOD (total_hours, 1) * 60
                  , 'fm00'
                   )     AS hh_mm,act_hour from(SELECT SUM (   TO_NUMBER (SUBSTR (act_hour, 1, 2))
                    + ( TO_NUMBER (SUBSTR (act_hour, 4, 2))
                      / 60
                      )
                    ) AS total_hours  
         from      pde)
    
    ORA-00904:''ACT_HOUR":invalid identifier
    Please help me
    thanking in advance
    Kind regards
    oracleuser

    Published by: makdutakdu on January 5, 2010 11:41

    Just push "with the clause" within the main request and give an alias of the table for him... something like

     SELECT TO_CHAR (FLOOR (total_hours))
      || ':'
      || TO_CHAR ( MOD (total_hours, 1) * 60 , 'fm00' ) AS hh_mm,
      empno                                                     ,
      act_hour
       FROM
      (SELECT SUM ( TO_NUMBER (SUBSTR (act_hour, 1, 2)) + ( TO_NUMBER (SUBSTR (act_hour, 4, 2)) / 60 ) ) AS total_hours
         FROM pde
      ) got_total_hours ,
      pde
    

    Ravi Kumar

  • need help with query xmltable

    Hello team,

    I have a problem by querying the xml file. Unable to get the correct result.

    XML:

    " < = xmlns:env env:Envelope ' http://schemas.xmlsoap.org/SOAP/envelope/ "xmlns:wsa =" " http://www.w3.org/2005/08/addressing ">

    < env:Header >

    < wsa: MessageID > urn: 93D110E0D6CD11E5BF8FC7751D1F819E < / wsa: MessageID >

    < wsa: ReplyTo >

    < wsa:Address > http://www.w3.org/2005/08/addressing/anonymous < / wsa:Address >

    < / wsa: ReplyTo >

    < / env:Header >

    < env:Body >

    " < = xmlns:client retrieveSubscriberDetailResponse ' http://xmlns.Oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess "xmlns =" http://xmlns.Oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess ">

    < customer: header >

    < customer: InterfaceName / >

    < customer: InterfaceId / >

    < customer: CorrelationId > Interface Sync n / < / customer: CorrelationId >

    < customer: ResultCode > 0 < / customer: ResultCode >

    < customer: ResultDescription > success < / customer: ResultDescription >

    < / customer: header >

    < customer: subscribers >

    < customer: Subscriber >

    < customer: subscriberId > 3891907 < / customer: subscriberId >

    < customer: serviceNo1 > 639372000342 < / client: serviceNo1 >

    < customer: serviceNo2 / >

    < customer: serviceNo3 > 515024400960403 < / client: serviceNo3 >

    < customer: serviceNo4 >

    < / customer: Subscriber >

    < / customer: subscribers >

    < / retrieveSubscriberDetailResponse >

    < / env:Body >

    < / env:Envolope >

    Here's my query:

    Select x.* tmp_soap_data t,

    xmltable (xmlnamespaces ('http://schemas.xmlsoap.org/soap/envelope/"as"ns1","http://www.w3.org/2005/08/addressing"as"ns2", ))

                             ' ( http://xmlns.Oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess ' as 'ns3'),

    ' ns1:Envelope / ns1:Body/retrieveSubscriberDetailResponse/ns3:subscribers '

    in passing t.lob_data

    path of columns subs_id varchar2 (100) ' / ns3:Subscriber / ns3:subscriberId') x;

    but the result is NULL.

    I'm on the right track with my request?

    Best regards

    Nelz Ki

    It works

    WITH tmp_soap_data as (select xmltype('
      
        
          
            
              3891907
              639372000342
              
              515024400960403
              
      
        
      
       
    ') lob_data from dual)
    -- Above is dummy setup to mimic your data tables
    select x.*
      from tmp_soap_data t,
           xmltable(xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope/' as "ns1",
                                  'http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess' as "ns3"),
                    'ns1:Envelope/ns1:Body/ns3:retrieveSubscriberDetailResponse/ns3:subscribers/ns3:Subscriber'
                    passing t.lob_data
                    columns
                    subs_id varchar2(100) path 'ns3:subscriberId') x;
    

    You were close.

    I made several minor changes.  Been cut down XML to remove the nodes not used for readability, typos corrected in the node names, removed the namespace ns2 is not mentioned in the XPath expressions, changed XPath primary as assuming that the client node: Subscriber could repeat, changed the XPath for the subs_id accordingly noticed that the node retrieveSubscriberDetailResponse uses the same URI for two namespaces, has added the ns3 prefix to retrieveSubscriberDetailResponse in the Xpath expression since it resides is in a default namespace and prefix ns3 points to this default namespace.

  • Need help with query to get days of work there are using the calendar BOM

    RDBMS: 10.2.0.4.0
    Oracle Applications: 11.5.10.2

    I try to use the BOM existing in the EBS to calculate working days calendar, there is a report that I am train. The BOM calendar presents the working days and non-working with the weekend days and holidays listed as non-working days. The following query gives correct results, but I'm looking for two different ways to do the same without "the union. I have nothing against the "unions", but I feel that I'm missing a more elegant to get there way. The query will in Discoverer Plus 10.1.2.3, so using a statement 'By' is not supported.
    sample data
    
    calendar_code                calendar_date                 seq_num                     
    SAC-WRKDAY                   12/3/2010                     1817
    SAC-WRKDAY                   12/4/2010                                                              
    SAC-WRKDAY                   12/5/2010                                                              
    SAC-WRKDAY                   12/6/2010                     1818                                 
    SAC-WRKDAY                   12/7/2010                     1819                                 
    SAC-WRKDAY                   12/8/2010                     1820     
    SAC-WRKDAY                   12/9/2010                     1821
    SAC-WRKDAY                   12/10/2010                    1822
    SAC-WRKDAY                   12/11/2010                   
    SAC-WRKDAY                   12/12/2010
    SAC-WRKDAY                   12/13/2010                    1823             
    select calendar_code
         , calendar_date
         , seq_num
         , sum(decode(bcd.seq_num,null,0,1))over(partition by bcd.calendar_code order by bcd.calendar_date desc) workdays_ago
    from   bom.bom_calendar_dates bcd
    where  calendar_code = 'SAC-WRKDAY'     
    and    trunc(bcd.calendar_date) < trunc(sysdate)
    
    union
    
    select calendar_code
         , calendar_date
         , seq_num
         , -sum(decode(bcd.seq_num,null,0,1))over(partition by bcd.calendar_code order by bcd.calendar_date ) workdays_ago
    from   bom.bom_calendar_dates bcd
    where  calendar_code = 'SAC-WRKDAY'
    and    trunc(bcd.calendar_date) > trunc(sysdate)
    sample output
    
    calendar_code                calendar_date                 seq_num                      workdays_ago
    SAC-WRKDAY                   12/3/2010                     1817                                  3
    SAC-WRKDAY                   12/4/2010                                                           2
    SAC-WRKDAY                   12/5/2010                                                           2
    SAC-WRKDAY                   12/6/2010                     1818                                  2
    SAC-WRKDAY                   12/7/2010                     1819                                  1
    SAC-WRKDAY                   12/9/2010                     1821                                 -1
    SAC-WRKDAY                   12/10/2010                    1822                                 -2
    SAC-WRKDAY                   12/11/2010                                                         -2
    SAC-WRKDAY                   12/12/2010                                                         -2
    SAC-WRKDAY                   12/13/2010                    1823                                 -3

    Hello

    Of course, you should be able to combine these queries, something like this:

    select calendar_code
         , calendar_date
         , seq_num
         , sum ( CASE
               WHEN  bcd.seq_num IS NULL
               THEN  0
               WHEN  bcd.calendar_date < TRUNC (SYSDATE)
               THEN  1
               ELSE  -1
              END
            ) over ( partition by  bcd.calendar_code
                  ,            SIGN (SYSDATE - bcd.calendar_date)
                  order by        ABS  (SYSDATE - bcd.calendar_date)
                ) workdays_ago
    from   bom.bom_calendar_dates bcd
    where  calendar_code = 'SAC-WRKDAY'
    and    trunc(bcd.calendar_date) < trunc(sysdate)
    

    If you do not want to display some CREATE TABLE and INSERT statements for the sample data, and then I could test it.

    t_norwillo wrote:
    ... I have nothing against the "unions", but I feel that I'm missing a more elegant to get there way.

    Good thinking!
    When the two branches of the UNION query the same table, there is usually a more effective way: something that only requires a pass through the table.

  • Need help with query outputing group names

    I'm trying to find a way for groups of output headers, then all the records in each group etc header. It would be easy, except there is a key with what I want to do.

    Normally, if I have this data set (that I've ' borrowed' a site that showed the closest to what I was looking for):

    Example table:

    TABLE [number]

    (Name, NUMBER)

    Dave Bower 843-444-4444

    Dave Bower 843-555-5555

    Matthew Small 843-111-1111

    Matthew Small _843-222-2222

    Matthew Small 843-333-3333

    I could use the following code:

    < cfoutput query = "somequery" group = "name" >

    #name # < br >

    < cfoutput >

    #phonenumber # < br >

    < / cfoutput >

    < hr >

    < / cfoutput >

    And get this:

    Dave Bower

    843-444-4444.

    843-555-5555.

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

    Matthew Small

    843-111-1111.

    843-222-2222.

    843-333-3333.

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

    BUT my actual tables are not set up like that. Rather than recording of every name of every record, I would have an ID that is the foreign key to another table.

    Current table set up is as follows:

    TABLE [people]

    (ID, NAME)

    1 Dave Bower

    2 small Matthew

    TABLE [Phones]

    (PEOPLE_ID NUMBER)

    1 843-444-4444

    1 843-555-5555

    2 843-111-1111

    2 843-222-2222

    2 843-333-3333

    If this output actually would this give me with my current setup and request above code:

    1

    843-444-4444.

    843-555-5555.

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

    2

    843-111-1111.

    843-222-2222.

    843-333-3333.

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

    How can I keep my current setup but create a query that produces the same result from the top? (The table names of people like the group headers, but data from the phones table under that output)

    You must gather the two tables, and then group the output.

    Something along the lines of the (may vary slightly depending on your DB and the exact table structure)

    SELECT ppl.name, ph.number

    PEOPLE ppl

    INNER JOIN phones ph ON ppl.id = ph.people_id

    ORDER BY ppl.name

    See you soon

    Kai

  • Need help with query to sort the Digital Alpha channels.

    Hello
    I have data like A2-1 A2-2 A2-3 A2-4 A4-S 10 - A2 A2-22 A5 - 15 16 A5 A5-1 has A5-1 b
    I want the data in a sequence sorted as A2-1 A2-2 A2 - 3 4 - A2 A2 10 A2-22 S A4 A5-1 has A5-1B A5-15 A5-16

    How to get there. Help, please.

    Perhaps that would help you

    with data as
        (
           select 'A2-1' LOCATION_DESC  from dual union all
           select 'A2-2'  as col1 from dual union all
           select 'A2-3'  as col1 from dual union all
           select 'A2-4'  as col1 from dual union all
           select 'A4-S'  as col1 from dual union all
           select 'A2-10' as col1 from dual union all
           select 'A2-22' as col1 from dual union all
          select 'A5-15' as col1 from dual union all
          select 'A5-16' as col1 from dual union all
          select 'A5-1A' as col1 from dual union all
          select 'A5-1B' as col1 from dual
      )
    SELECT * FROM data
    order by SUBSTR(LOCATION_DESC,2,INSTR(LOCATION_DESC,'-')-2);
    

    * 009 *.

  • Need help with query below

    Hi experts,

    Since the code mentioned below, I get the previous quarter start and end date:
    SELECT MIN (t), MAX (LAST_DAY (t)) INTO V_PRVQTD_STRT,V_PRVQTD_END
            FROM (SELECT ADD_MONTHS (TRUNC(TO_DATE(V_RPRT_DATE), 'YYYY'), LEVEL - 1) t,
                      TO_CHAR (ADD_MONTHS (TRUNC(TO_DATE(V_RPRT_DATE), 'YYYY'), LEVEL - 1), 'Q')QTD
            FROM DUAL
                     CONNECT BY LEVEL <= 12) A
                       WHERE A.QTD  = V_QUARTER_NUMBER-1
    but when I'm passing all the date in the first quarter according to the calendar year, ranging from 01-jan-YYYY and YYYY-Mar-31 he gives no value as subtracting quarter number V_QUARTER_NUMBER-1 m - 1.

    Can any1 help me to overcome this problem as its very urgent...

    Help appreciated

    Thnx in advance.

    If you are looking for the previous date of beginning and end of quarter, then you can use below

    SELECT   ADD_MONTHS(MIN (t),-3), ADD_MONTHS(MAX (LAST_DAY (t)),-3) -----------------code change
            FROM (SELECT ADD_MONTHS (TRUNC(TO_DATE(TO_DATE('01012012','DDMMYYYY')), 'YYYY'), LEVEL - 1)  t,
                      TO_CHAR (ADD_MONTHS (TRUNC(TO_DATE(TO_DATE('01012012','DDMMYYYY')), 'YYYY'), LEVEL - 1), 'Q')QTD
            FROM DUAL
                     CONNECT BY LEVEL <= 12) A
                       WHERE A.QTD  = 4;  -----change quater as per your requirement
    

    You can do both in the same essay

    SELECT   MIN (t)"CURNT_QTR_ST_DT", MAX (LAST_DAY (t))"CURNT_QTR_END_DT", ADD_MONTHS(MIN (t),-3) "PREV_QTR_ST_DT" , ADD_MONTHS(MAX (LAST_DAY (t)),-3) "PREV_QTR_END_DT"
            FROM (SELECT ADD_MONTHS (TRUNC(TO_DATE(TO_DATE('01012012','DDMMYYYY')), 'YYYY'), LEVEL - 1)  t,
                      TO_CHAR (ADD_MONTHS (TRUNC(TO_DATE(TO_DATE('01012012','DDMMYYYY')), 'YYYY'), LEVEL - 1), 'Q')QTD
            FROM DUAL
                     CONNECT BY LEVEL <= 12) A
                       WHERE A.QTD  = 1;
    Output
    -----------
    CURNT_QTR_ST_DT     CURNT_QTR_END_DT     PREV_QTR_ST_DT     PREV_QTR_END_DT
    1/1/2012     3/31/2012     10/1/2011     12/31/2011
    

    Published by: myOra_help on December 27, 2012 17:50

  • Need help with Query Rewrite

    I have the SQL which contains a scalar subquery. I need to move the FROM clause scalar subquery. Please note that there is an OUTER JOIN in SQL.
    select CHDR.CHDRNUM POLICY_ID,
           CHDR.COWNNUM POL_OWNER,
           (Select Lifcnum
                     From Odslifeasia.Lifepf
                    Where Life = '01'
                      And Jlife = '00'
                      And Validflag <> '2'
                      AND CHDRNUM = CHDR.CHDRNUM
                      and rownum = 1) LIFE_ASSURED,
           CHDR.BILLCHNL,
          ( Select Facthous
             From Odslifeasia.Clbapf Clba, Odslifeasia.Mandpf Mand
            Where Clba.Validflag = '1'
              And Clba.Clntnum = mand.Payrnum
              And Clba.Clntcoy = Mand.Payrcoy
              And Clba.Bankacckey = Mand.Bankacckey
              And (Mand.Payrnum = Chdr.Payrnum Or
                  Mand.Payrnum = Chdr.Cownnum)
              And (Mand.Payrcoy = Chdr.Payrcoy Or
                  Mand.Payrcoy = Chdr.Cowncoy)
              And Mand.Mandref = Chdr.Mandref
              And Chdr.Billchnl In ('D', 'K', 'S')
              And Mand.Validflag = '1'
              And Mand.Mandstat = '10'
              and rownum = 1) Facthous,
               ACM_DATE,
              (Select Dc.Longdesc
              From Odslifeasia.Descpf Dc
             Where Dc.Descitem = CHDR.BILLCHNL
               And Dc.Desctabl = 'T3620'
               And DC."LANGUAGE" = 'E'
               And Dc.Desccoy = '2'
               And Dc.Descpfx = 'IT'
               And Rownum = 1) BILL_CHNL_NAME
           from odslifeasia.chdrpf chdr
           left outer join
             (SELECT chdrnum, MAX(DATESUB) acm_date FROM ODSLIFEASIA.PTRNPF
              WHERE PTRNPF.Batctrcde = 'B673' group by chdrnum) PTRN on (ptrn.CHDRNUM = chdr.CHDRNUM)
           where CHDR.VALIDFLAG IN ('1', '3');

  • Need help with a query result

    Oracle Version: 11.2.0.2.0

    I need assistance with the output of the query. Here is the table.

    With Tbl_Nm as

    (

    Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select * from tbl_nm

    I need the output below.

    PQR2 UK MC 2600 1 OCTOBER 2012 04:45

    ABC1 US NY 3500 October 1, 2012 06:45

    LMN3 UK BT 2500 November 1, 2012 07:45

    The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.

    I've tried a few and got stuck. Help, please. Not able to get a balance '.

    This question is a bit similar to needing help with a query result

    With Tbl_Nm as

    (

    Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1

    where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)

    So maybe you'd then

    ORDER BY DECODE(flag,'D',9,1) ASC...

    to get the Ds at the end of the list.

    or

    ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...

    HTH

Maybe you are looking for

  • Can ios10 use 9.3.5 password entry page?

    Updated to 10 of 6 s, 64 GB. I found this slide left leads to another page. Can I set up to use ios 9 password page?

  • Satellite A100-192 - high CPU temperature

    Hello I have this laptop for several months. Up to now, cpu temp was about 63 degrees Celsius at the Summit. Since a few days temp is 63 maximum idle and 73 when... the game worms 2!What could go wrong? There is nothing that would drain my cpu, nothi

  • Logic of long-standing problem - help requested

    3.6.1 numbers using I am trying to improve the process that I do in my work. I have download and regularly need to massage ~ 850 lines of spreadsheet data but the variables seem to be either impossible to work with or the method required beyond my co

  • Multiple DaqBoards in Dasylab

    According to the Manual (which is 6 years old) for IOTech DaqBoard 1000-series can only be used with a DaqBoard both Dasylab. Is this true for the latest version of Dasylab?

  • Y at - it a State chart type or the flowchart describing the order of execution process model?

    One of my clients asked me this question... I have a problem with a change in the order of execution in TestStand 4.1.1.  [he has improved from 3.1 to 4.1.1]  It seems that ProcessModelPreStep runs earlier in 4.1.1 to 3.1.  This causes our model of e