Is this possible in a single query?????

While I don't think this is possible in a single query, I definately don't have the background the experts here have. 
I have a request to identify all shipments in a period/range of periods that have a payment transaction.  For those shipments, the user wants a list of all payment transactions and the initial accrual entry listed by period for potentially a large range of periods.  The accrual and payment entries are identifed by the same characteristic and a 0Amount key figure contains the values.  A couple methods I have tried I have listed in previous threads with either errors or the query blowing up with what appears to be a cartesian product issue.
Anyone done something like this who can provide pointers.
Bill

Hi Bill,
Why dont u use RRI-report to report interface for this Requierment ??
There are lots of threads on RRI ,just follow them and u can satisfy this requirement.
1)Query A for Shipments
2)Query B for Payment Transactions.
Call report B from Report A
1)GOTO RSBBS
2)Create New
3)Sender Query Give the First Query Report A
4)Below sender Query there is Receiver Query  give the RRI query report B (The query which u want to call).Report type should be BEX ,and Target system--Assign the System(Local) and in the report give the Report B.
5)In the Report A check whether in the GOTO -u get the Receiver Query ,i.e Report B.
Hope this help !!!!!!!!!
Rgds
SVU123

Similar Messages

  • Possible in a single query ...?

    We have one question master table as...
    questionnumber number(3),
    answer char(1)
    And another table candidate_choice table as...
    candidatesrno number(6),
    questionnumber number(3),
    answer char(1),
    marks number(5,2)
    Candidate entries are stored in candidate_choice table. Now we have to prepare marks sheet. For this we need to compare each candidate's answer with question master table and it it matches, we have to give 1 mark. And if it does not match we have to give -1 marks. And total marks is to be stored in marks column of candidate_choice table.
    How can we write single SQL query to do this ?
    (we are using Oracle 9i R. 2)
    Thanks,
    Kiran Shah.

    Nice point Kamal. I forget to give one Candidate master table details.
    So actually is goes like this...(with little modification in Candidate_choice table)
    Table : Candidate master
    create table jacademy(
    candidatesrno number(6),
    name varchar2(100),
    Marks number(5,2))
    Values
    insert into jacademy values(1, 'Kiran Shah', NULL)
    insert into jacademy values(2, 'Ramesh Mande', NULL)
    insert into jacademy values(3, 'Saseendran', NULL)
    question master table as...
    create table qmaster(
    questionnumber number(3),
    answer char(1))
    values
    insert into qmaster values(1, 'T')
    insert into qmaster values(2, 'F')
    insert into qmaster values(3, 'T')
    And another table candidate_choice table as...
    create table candidate_choice(
    candidatesrno number(6),
    questionnumber number(3),
    answer char(1))
    values
    insert into candidate_choice values(1,1,'T')
    insert into candidate_choice values(1,2,'T')
    insert into candidate_choice values(1,3,'F')
    Now we have to prepare marks sheet. For this we need to compare each candidate's answer with question master table and it it matches, we have to give 1 mark. And if it does not match we have to give -1 marks. And total marks is to be stored in marks column of candidate master table.
    Thanks...

  • Getting result with single query

    Hi,
    I'm using db 10.2.0.1.0
    I have a table emp_shift , with data like below
    EmpCode           Shift     Effdate            Default
    1                 SHFT1    02-jan-2012          N
    1                 SHFT2    04-jan-2012          Y
    1                 SHFT3    04-jan-2012          NSo if user inputs EmpCode and Effdate, based on that i've to take the latest record, with default = 'Y' (if any) else default 'N'
    Suppose
    Case 1 : Input Empcode:1 Date:10-jan-2012
    Then i should get the below record
    1                 SHFT2    04-jan-2012          YCase 2 : Input Empcode:1 Date:03-jan-2012
    Then i should get the below record
    1                 SHFT1    02-jan-2012          NI want this result with a single query, is this possible?
    Thanks
    Divya

    Hi Thank you both,
    I'm trying this process through forms. and my forms version is 6i.
    There where i'm trying the query with the cursor, i'm getting error
    Encountered the symbol Order when expecting one of the following
    .()...and my cursor is
    Cursor cur_shft(vemp Varchar2,vdate Varchar2) is Select ESM_SHIFT_TYPE
         from (Select ESM_SHIFT_TYPE from EMPLOYEE_SHIFT_MASTER
                   Where ESM_EMP_CODE = vemp
                   and ESM_EFF_DATE <= vdate
                   Order by ESM_EFF_DATE desc,Esm_Default desc)
                   Where rownum=1 ;Whats wrong?

  • Is a single Query possible for this?

    Hi everyone,
    I have a requirement to get a list of 10 free (non-assigned) ids from a table. The ids range from say 1-32000. The table contains only the assigned ids. So the idea is - if say we have 15 records already in this table like 2,7,23,4,65,22,665... etc (random, non-repeated, unsorted values), then I need to get the first 10 numbers in the range 1-32000 which are not there in the table e.g. 1,3,4,5,6,8,...etc. One idea is to have a table2 with a single column having values 1-32000 i.e. 32000 rows. Then we can give the query like -
    select col1 from table2 where rownum<=10 and col1 not in (select id from table1);
    Is there a better way to get this output without having a separate table with 32000 rows? Or, is it possible to form a faster query even with the proposed solution?
    Thanks,
    Regards
    Sanchayan
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by [email protected]:
    Hi everyone,
    I have a requirement to get a list of 10 free (non-assigned) ids from a table. The ids range from say 1-32000. The table contains only the assigned ids. So the idea is - if say we have 15 records already in this table like 2,7,23,4,65,22,665... etc (random, non-repeated, unsorted values), then I need to get the first 10 numbers in the range 1-32000 which are not there in the table e.g. 1,3,4,5,6,8,...etc. One idea is to have a table2 with a single column having values 1-32000 i.e. 32000 rows. Then we can give the query like -
    select col1 from table2 where rownum<=10 and col1 not in (select id from table1);
    Is there a better way to get this output without having a separate table with 32000 rows? Or, is it possible to form a faster query even with the proposed solution?
    Thanks,
    Regards
    Sanchayan<HR></BLOCKQUOTE>
    Sanchayan,
    Your problem can be solved by a single query.
    Try the following query:
    (THIS WILL GIVE AN IDEA")
    select * from (
    select rownum from (select numero from srm_test)
    minus
    select numero from srm_test)
    where rownum < 10
    order by 1
    YOU WILL GET:
    ROWNUM
    1
    3
    6
    8
    10
    11
    12
    7 rows selected.
    The contents of srm_test are:
    2, 7, 23, 4, 65, 22, 665, 90, 87, 200, 9, 5
    null

  • Can this be done by just a single query alone ?

    hi ,
    I have the following data
    id , type1 , duration, status
    1 a 2 R
    1 a 3 R
    1 a 2 I
    i need to become a single record as follows
    id , type total , total_R , total I
    1 a 7 4 2
    partitition by does not allow where clause
    besides 1st creating a table and then update the fields , is this possible in just using 1 query (besides unioning several query for total_R , total_I) ?
    pls advise
    tks & rgds

    select id , case when type like '%I' then sum(time1)
    end case total_1
    group by id , -- if i do not speciy type it won't
    work but what i want is a total over each different
    idpls adviseSum should come outside the case statment. Try this
    select id , sum(case when type like '%I' then time1 end) total_1
    group by id There is no performance difference between case and decode.

  • Is it possible to run 2 different reports SEPARATELY from a single query?

    Dear All,
    The title to my previous thread seems to be inaccurate and misleading.
    To encourage people to read it, I am giving it a more appropriate Title.
    Please do not reply on this thread, but refer to the original one.
    Thanks
    Leon Lai
    Here's the link:
    Is it possible to combine 2 different reports in a single Query?

    Dear All,
    The title to my previous thread seems to be inaccurate and misleading.
    To encourage people to read it, I am giving it a more appropriate Title.
    Please do not reply on this thread, but refer to the original one.
    Thanks
    Leon Lai
    Here's the link:
    Is it possible to combine 2 different reports in a single Query?

  • Hi, I have got three ipad minis which I would like to use in a business environment whereby the users can see and update a single calender.  Is this possible? Would they have to be run form one account?

    Hi, I have got three ipad minis which I would like to use in a business environment whereby the users can see and update a single calender.  Is this possible? Would they have to be run form one account?

    Drrhythm2 wrote:
    What's the best solution for this? I
    Copy the entire /Music/iTunes/ folder from her old compouter to /Music/ in her account on this new computer.

  • Is it possible to get this o/p in a query

    Hello All,
    is it possible to write a query for the output
    SQL> select * from emp1;
    EMPNO EMPNAME
    100 AAA
    222 BBB
    333 CCC
    444 DDD
    SQL> select * from bank;
    BANKID BANKNAME
    1 ICICI
    2 HDFC
    3 SBI
    4 SBH
    SQL> select * from emp1_bank;
    EMPNO BANKID
    100 1
    100 4
    222 3
    222 2
    333 1
    444 3
    6 rows selected.
    Now I want output like this
    1 2 3 4
    100 Y Y
    222 Y Y
    333 Y
    444 Y

    Hi,
    create or replace function bank_head return varchar2 is
    v_bankh varchar2(2000) :='';
    begin
    for i in (select bankname from bank order by bankid)
    loop
    v_bankh := v_bankh || substr(i.bankname,1,3) || ' ';
    end loop;
    return v_bankh;
    end;
    create or replace function bank_detl(p_empno number) return varchar2 is
    v_bankc varchar2(2000);
    cursor c1 is select bankid from bank;
    v_id number;
    begin
    open c1;
    for i in (select bankid from emp1_bank where empno=p_empno order by 1)
    loop
    loop
    fetch c1 into v_id;
    exit when c1%notfound;
    if i.bankid = v_id then
    v_bankc := v_bankc || ' Y ' || ' ';
    exit;
    else
    v_bankc := v_bankc || ' ' || ' ';
    end if;
    end loop;
    end loop;
    close c1;
    return v_bankc;
    exception when others then
    return null;
    end;
    1 select 'emp ',substr(bank_head,1,100) from dual
    2 union all
    3* select substr(to_char(empno),1,3),substr(bank_detl(empno),1,100) from emp1
    SQL> /
    'EMP SUBSTR(BANK_HEAD,1,100)
    emp ICI HDF SBI SBH
    100 Y Y
    222 Y Y
    333 Y
    444 Y
    It is Ok With you
    Bye
    chitta

  • I need to generate a still shot from from a video. I would like to accomplish this task using a single application. If this is not possible with my MacBook Pro as purchased from Apple, please recommend which applications I can purchase.

    I need to generate a still shot from from a video I made with my camera. I would like to accomplish this task using a single application. If this is not possible with my MacBook Pro as purchased from Apple, please recommend which applications I can purchase that include this feature. Thanks in advance.

    For FREE do the following:
    When you get to othe part of the video you want a still shot from, put the video on pause. 
    Take a screen shot:  Apple>Shift>4 - which will produce a cross hair so you can manually select which part of the video you want.Check inside either your Applications or Utility folder for an app called Grab.  Will do the above with just a single click.
    If you still want to purchase software, suggest that you do a Google & MacUpdate search.  This way, you can find exactly what you want. 

  • Is it possible to combine 2 different reports in a single Query?

    Dear All,
    What am I working at?
    I produced a Query for Debtors Aged Analysis which mimics the Official SAP B1 8.8 Aging Report.
    It ages the outstanding invoices by Posting Date ( RefDate  in JDT1)
    I also made another Report which ages outstanding amounts by Document Date simply by replacing all RefDate by TaxDate
    They give different answers if Posting Date is different from Document Date, e.g a manual invoice dated 5 Jun 2011 is posted on 2 Jul 2011.
    What I want to do?
    My idea is to produce a SINGLE QUERY which will generate either Aging depending on settings:
        (a) A Debtors Aging by Posting Date
        (b) A Debtors Aging by Document Date
    I declare 2 variables:
    (a) @refdt  is [%1] and represents Posting Date (JDT1 RefDate)
    (b) @taxdt  is [%2] and represents Document Date (JDT1 TaxDate)
    When the Query is run, the foll dialog appears:
    Query - Selection Criteria
    Posting Date             Equal .......
    Document Date            Equal .......
    OK   Cancel
    We are expected to fill in only 1 date and leave the other blank, and Query will generate the required report .
    What is my problem?
    Query runs smoothly, but amounts in the Balance column does not get analyzed in the Age brackets: Current / 1 Mth Ago / etc
    I think I know where's the problem
    I am assuming (wrongly) that if we don't fill one date field, the query returns NULL for that variable. In fact, it appears to return GetDate().
    Help
    Can anybody help me put the correct commands so that all my balances are correctly analysed in the respective age buckets?
    Thanks
    Leon Lai
    Here's a simplified SQL:
    Tables  :
          JDT1   T0  = Journal Entry - Rows
          OCRD T1 = Business Partner
          OCPR T2 = Contact Person
          OJDT  T3  = Journal Entry - Header
          OINV   T4  = A/R Invoices - Header
          ORIN   T5  - A/R Credit Memo - Header
    declare @refdt date
    declare @taxdt date
    set @refdt
    /*Select 1 from jdt1 t where t.RefDate*/ = [%1]
    set @taxdt
    /*Select 1 from jdt1 w where w.TaxDate*/ = [%2]
    SELECT
    'company1' AS 'Company',
    T1.CardCode  AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    T0.RefDate AS 'Pstg Dt',
    T0.TaxDate AS 'Doc Dt',
    CASE
             WHEN T0.TransType = 13 THEN 'IN'
             WHEN T0.TransType = 14 THEN 'CN'
             WHEN T0.TransType = 30 THEN 'JE'
             WHEN T0.TransType = 24 THEN 'RC'
             WHEN T0.TransType = 46 THEN 'PS'
             ELSE 'Error ! ! !'
    END AS 'Doc Type',
    T0.Ref1 'Doc. Number',
    ISNULL(T0.FCCurrency, ' - ') AS 'Ccy',
    (T0.FCDebit - T0.FCCredit) AS 'Orig. F.Ccy',
    (T0.BalFcDeb - T0.BalFcCred) AS 'Bal. F. Ccy',
    (T0.Debit - T0.Credit) AS 'Orig. Rs',
    (T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',
    /* ########################  PROBLEM is here   ################## */
    CASE
                   WHEN (@refdt is not null) and (@taxdt is null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                   WHERE DateDiff(mm, T0.RefDate, @refdt) = 0 ) ,0)
                   WHEN (@refdt is null) and (@taxdt is not null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                    WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 0 ) ,0)
    END AS 'Current Mth', 
    CASE
                   WHEN (@refdt is not null) and (@taxdt is null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                   WHERE DateDiff(mm, T0.RefDate, @refdt) = 1 ) ,0)
                   WHEN (@refdt is null) and (@taxdt is not null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                    WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1 ) ,0)
    END AS '1 Mth Ago'
    /* Similarly for other age buckets  */
    FROM company1.dbo.JDT1 T0
    INNER JOIN company1.dbo.OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN company1.dbo.OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN company1.dbo.OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN company1.dbo.OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN company1.dbo.ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C' and Balance != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0

    HI
    I generate the next aged analysis
    CREATE PROCEDURE [dbo].[Aged_Analysis] (@end datetime,@Client VarChar (20)) AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    Declare @SAPUNION Table (SN VarChar(50), TransId Int, ReconSum Decimal(19,2), DebHab VarChar(1),
                                       Linea Int)
    insert into @SAPUNION
    SELECT X0.ShortName 'SN', X0.TransId 'TransId', SUM(X0.ReconSum)'ReconSum', X0.IsCredit 'DebHab', X0.TransRowId 'Linea'
                FROM ITR1 X0
                INNER JOIN OITR X1 ON X1.ReconNum = X0.ReconNum
                WHERE X1.ReconDate <= @end  AND X1.CancelAbs = ''
                GROUP BY X0.ShortName, X0.TransId, X0.IsCredit, X0.TransRowId
    SELECT T0.CardCode, T0.CardName,T0.Address,T0.CreditLine,
    T1.TransId , T4.BaseRef , T1.Ref2 , T1.RefDate, T1.DueDate,
    CASE
          WHEN T3.DebHab = 'D'  THEN T1.Debit-T1.Credit-T3.ReconSum
          WHEN T3.DebHab = 'C'  THEN T1.Debit-T1.Credit+T3.ReconSum
          ELSE (T1.Debit-T1.Credit)
    END 'Balance',
    CASE
           when DateDiff(Day,t1.RefDate,GetDate()) <= 30 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.RefDate,GetDate()) <= 30 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.RefDate,GetDate()) <= 30 then (T1.Debit-T1.Credit) end '0-30 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 then (T1.Debit-T1.Credit) end '31-45 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 then (T1.Debit-T1.Credit) end '46-60 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 then (T1.Debit-T1.Credit) end '61-75 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 then (T1.Debit-T1.Credit) end '76-89 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) >90 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) >90 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) >90 then (T1.Debit-T1.Credit) end '90-Mas',
    CASE T1.TransType
          WHEN '13' THEN (SELECT Y.Comments FROM OINV Y WHERE Y.TransId = T1.TransId)
          WHEN '14' THEN (SELECT Y.Comments FROM ORIN Y WHERE Y.TransId = T1.TransId)
          WHEN '24' THEN (SELECT Y.Comments FROM ORCT Y WHERE Y.TransId = T1.TransId)
          ELSE T1.LineMemo
    END 'Comments'
    FROM OCRD T0
          INNER JOIN JDT1 T1 ON T1.ShortName = T0.CardCode
          INNER JOIN OACT T2 ON T2.AcctCode = T1.Account
          INNER JOIN OJDT T4 ON T4.TransId = T1.TransId
          LEFT JOIN OINV T5 ON T5.TransId = T4.TransId  and t5.ObjType = t4.TransType     
          LEFT JOIN @SAPUNION T3 ON T3.TransId = T1.TransId AND T3.SN = T1.ShortName AND T3.Linea = T1.Line_ID
    WHERE T0.CardType = 'C' /*FOR CLIENTS*/ AND T1.RefDate <= @end AND T2.AcctCode = /*YOUR CLIENT ACCOUNT*/ AND
    (CASE
          WHEN T3.DebHab = 'D' THEN (T1.Debit-T1.Credit-T3.ReconSum)
          WHEN T3.DebHab = 'C' THEN (T1.Debit-T1.Credit+T3.ReconSum)
          ELSE (T1.Debit-T1.Credit)
    END) != '0'
    AND T0.CardCode= @Client
    ORDER BY T0.CardCode,T1.TransId,t1.Ref2
    END
    AND Execute by SAP
    DECLARE @VAR INT, @DATE DATETIME, @BP VARCHAR(8)
    SET @VAR = (SELECT TOP 1 T.DocEntry FROM [dbo].[OINV] T WHERE T.DocDate <='[%0]' AND T.CardCode='[%1]')
    SET @DATE = '[%0]'
    SET @BP = '[%1]'
    EXECUTE [dbo].[Aged_Analysis]
    @end = @DATE,
    @Client = @BP
    Regards
    Floyola
    Edited by: Floyola on Jul 22, 2011 10:17 AM

  • How to get this with Single query

    Friends
    I am sure using SQL analytical function, the following can be achieved using a single query:
    Date_value | Cust_id | Customer_tenue | avg_bal
    01-aug-09 | 111 | 0 | 1000
    01-aug-09 | 112 | 1 | 2000
    01-aug-09 | 113 | 2 | 900
    01-aug-09 | 114 | 3 | 1250
    01-sep-09 | 111 | 1 | 1200
    01-sep-09 | 112 | 2 | 2000
    01-sep-09 | 113 | 3 | 1900
    01-sep-09 | 114 | 4 | 1250
    01-oct-09 | 111 | 2 | 1100
    01-oct-09 | 112 | 3 | 2200
    01-oct-09 | 113 | 4 | 1900Expected result
    If customer’s tenure is 0 then mark as ‘New’,
    If customer’s balance is increased from last month then mark as ‘Augment’
    If customer’s balance is same as last month then mark as ‘Maintain’
    If customer’s balance is decreased from last month then mark as ‘Diminish’
    Else ‘Left’
    Help please....

    If customer’s tenure in last month is 0 then mark as ‘New’,There's not such case in test data... last month is October, isn't it?
    SQL> with t as (select DATE '2009-08-01' Date_value, 111 Cust_id, 0 Customer_tenue, 1000 avg_bal from dual union all
      2  select DATE '2009-08-01', 112 , 1 , 2000 from dual union all
      3  select DATE '2009-08-01', 113 , 2 , 900 from dual union all
      4  select DATE '2009-08-01', 114 , 3 , 1250 from dual union all
      5  select DATE '2009-09-01', 111 , 1 , 1200 from dual union all
      6  select DATE '2009-09-01', 112 , 2 , 2000 from dual union all
      7  select DATE '2009-09-01', 113 , 3 , 1900 from dual union all
      8  select DATE '2009-09-01', 114 , 4 , 1250 from dual union all
      9  select DATE '2009-10-01', 111 , 2 , 1100 from dual union all
    10  select DATE '2009-10-01', 112 , 3 , 2200 from dual union all
    11  select DATE '2009-10-01', 113 , 4 , 1900 from dual)
    12  select date_value, cust_id, avg_bal, oldbal, case when Customer_tenue=0 and nextbal is null then 'NEW'
    13                                                    when oldbal<avg_bal then 'Augment'
    14                                                    when oldbal=avg_bal then 'Maintain'
    15                                                    when oldbal>avg_bal then 'Diminish'
    16                                                    else 'Left' end status
    17    from (select date_value, cust_id, customer_tenue, avg_bal, LEAD(avg_bal) over (partition by cust_id order by date_value desc) oldbal,
    18                 LAG(avg_bal) over (partition by cust_id order by date_value desc) nextbal
    19            from t)
    20  order by cust_id, date_value;
    DATE_VALU    CUST_ID    AVG_BAL     OLDBAL STATUS
    01-AGO-09        111       1000            Left
    01-SET-09        111       1200       1000 Augment
    01-OTT-09        111       1100       1200 Diminish
    01-AGO-09        112       2000            Left
    01-SET-09        112       2000       2000 Maintain
    01-OTT-09        112       2200       2000 Augment
    01-AGO-09        113        900            Left
    01-SET-09        113       1900        900 Augment
    01-OTT-09        113       1900       1900 Maintain
    01-AGO-09        114       1250            Left
    01-SET-09        114       1250       1250 Maintain
    Selezionate 11 righe.Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • Multiple databases in a single query

    I need to query multiple databases in a single query.
    e.g.
    Database d1 contains table t1 with column id
    Database d2 contains table t2 with column id
    I need a query like
    SELECT * FROM t1, t2 WHERE t1.id = t2.id;
    is this possible in jdbc? if yes can anyone help with some sample code?
    thanks,
    Ashish Saraf

    It is not possible using the JDBC API to query tables in two or more databases using a single query. The reason is that a JDBC Connection is made to a single data source.
    However, some databases support the idea of federations or linked tables. What you do is inside the database manager link or federate a table that is present in another DBMS. Then, pose a single JDBC query to the one DBMS which will have its own table and links to the external tables.
    Another approach is to use a special JDBC driver with a built-in integration engine that will perform a query across multiple databases. In effect, the system poses separate queries to the different databases and integrates and joins the data together for you automatically on the client-side. That is much easier than doing it yourself in code, but that is also possible for simple queries.
    As part of my research program, we have released a shareware version of the UnityJDBC driver that can query multiple databases using a single SQL query. For more information, see:
    http://www.unityjdbc.com
    http://www.cs.uiowa.edu/~rlawrenc/research/projects.html
    Sincerely,
    Dr. Ramon Lawrence
    Assistant Professor
    Department of Computer Science
    University of Iowa
    [email protected]

  • All selected 'n' consecutive rows in retrieved in a single query

    hello,
    I have table T with 50,000 rows
    create table T
    (student_id number,
    class_id number,
    quiz_id number,
    marks number)
    some sample rows like
    INSERT INTO T VALUES (1,1, 1, 50);
    INSERT INTO T VALUES (2,2, 2, 40);
    INSERT INTO T VALUES (3,1, 3, 34);
    INSERT INTO T VALUES (1,1, 4, 10);
    INSERT INTO T VALUES (1,1, 5, 30);
    INSERT INTO T VALUES (1,1, 6, ‘29);
    INSERT INTO T VALUES (3,2, 7, 34);
    INSERT INTO T VALUES (3,2, 8, 33);
    INSERT INTO T VALUES (3,2, 9, 56);
    INSERT INTO T VALUES (1,1, 7, 90);
    INSERT INTO T VALUES (2,2, 8, 0,);
    INSERT INTO T VALUES (1,1, 8, 80);
    INSERT INTO T VALUES (2,2, 8, 65);
    INSERT INTO T VALUES (1,1, 9, ‘34);
    INSERT INTO T VALUES (2,2, 9, 11);each student belongs to one class_id. each student participates in many quizes. each quiz has its unique id. each student can appear once in a quiz_id
    I am doing the below analysis and query:
    1. with below query I am finding which student_id had most marks in any 3 successive quizes (see the 3-1 part below) in the query..
    SELECT QUIZ_ID,
          STUDENT_ID,
    SUM (MARKS) OVER (PARTITION BY STUDENT_ID ORDER BY QUIZ_ID1
    RANGE BETWEEN CURRENT ROW AND (3-1) FOLLOWING) consecMARKS , MARKS   FROM
          (SELECT QUIZ_ID,
            STUDENT_ID,
            MARKS,
          ROW_NUMBER() OVER (PARTITION BY STUDENT_ID ORDER BY T.QUIZ_ID) QUIZ_ID1
          FROM T
          WHERE MARKS IS NOT NULL
          ORDER BY 1
        ORDER BY 3 DESC
    SQL> /
       QUIZ_ID STUDENT_ID CONSECMARKS
             7          1         170
             6          1         166
             8          1         129
             5          1         106
             8          3          89
             8          2          76
             3          3          68
             7          3          67
             8          2          65
             1          1          60
             9          3          56
       QUIZ_ID STUDENT_ID CONSECMARKS
             9          1          49
             2          2          40
             4          1          40
             9          2          11
    15 rows selected.With above query, I can play around and find for any 'n' number of consecutive quizes, like marks in 2 consecutives quizes, 3, 4 and so on but for each 'n' value I've to run a seperate query mentioning (2-1) or (3-1) or (4-1) and so on..
    since my table is big and there are about 400 quizes so what I want to find out is for each 'n' consecutive quiz (from 1 to 400) which student had most marks for each consecutie 'n' quiz. Like in 1 (consecutive) quiz which student had the highest marks and then 2 conseuctive quiz who had most marks and then in 3 consecutive quiz who had most marks and so on till 400 consecutive quiz who had most marks... rather than running query for each 'n' value seperately i want a single query that can give me a summary of most marks in each n consecutive quizes...
    my sample output is:
    Nth consecutive quiz     student_id    sum(marks)
    1                        1              90
    2                        1              170
    3                        1              246
    4
    100
    200
    300
    400                      ?              ?   Is this possible to get the above output from one single query? If there are two or more students with equal most marks for any 'n' conseutive quizes then both should come in the summary.
    Hope I have been able to put up my question clearly.
    regards
    Ramis

    Something like:
    SELECT  N,
            QUIZ_ID,
            STUDENT_ID,
            SUM(MARKS) OVER (PARTITION BY N,STUDENT_ID ORDER BY QUIZ_ID1 RANGE BETWEEN CURRENT ROW AND (N-1) FOLLOWING) consecMARKS,
            MARKS
      FROM  (SELECT  QUIZ_ID,
                     STUDENT_ID,
                     MARKS,
                     ROW_NUMBER() OVER (PARTITION BY STUDENT_ID ORDER BY T.QUIZ_ID) QUIZ_ID1
               FROM  T
               WHERE MARKS IS NOT NULL
             SELECT  LEVEL N
               FROM  DUAL
               CONNECT BY LEVEL <= (
                                    SELECT  COUNT(DISTINCT QUIZ_ID)
                                      FROM  T
        ORDER BY N,
                 consecMARKS DESC
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             1          7          1          90         90
             1          8          1          80         80
             1          8          2          65         65
             1          9          3          56         56
             1          1          1          50         50
             1          2          2          40         40
             1          9          1          34         34
             1          7          3          34         34
             1          3          3          34         34
             1          8          3          33         33
             1          5          1          30         30
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             1          6          1          29         29
             1          9          2          11         11
             1          4          1          10         10
             1          8          2           0          0
             2          7          1         170         90
             2          6          1         119         29
             2          8          1         114         80
             2          8          3          89         33
             2          8          2          76         65
             2          3          3          68         34
             2          7          3          67         34
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             2          8          2          65          0
             2          1          1          60         50
             2          5          1          59         30
             2          9          3          56         56
             2          2          2          40         40
             2          4          1          40         10
             2          9          1          34         34
             2          9          2          11         11
             3          7          1         204         90
             3          6          1         199         29
             3          5          1         149         30
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             3          7          3         123         34
             3          8          1         114         80
             3          2          2         105         40
             3          3          3         101         34
             3          1          1          90         50
             3          8          3          89         33
             3          8          2          76         65
             3          8          2          76          0
             3          4          1          69         10
             3          9          3          56         56
             3          9          1          34         34
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             3          9          2          11         11
             4          6          1         233         29
             4          5          1         229         30
             4          7          1         204         90
             4          4          1         159         10
             4          3          3         157         34
             4          7          3         123         34
             4          1          1         119         50
             4          2          2         116         40
             4          8          1         114         80
             4          8          3          89         33
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             4          8          2          76          0
             4          8          2          76         65
             4          9          3          56         56
             4          9          1          34         34
             4          9          2          11         11
             5          5          1         263         30
             5          4          1         239         10
             5          6          1         233         29
             5          1          1         209         50
             5          7          1         204         90
             5          3          3         157         34
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             5          7          3         123         34
             5          2          2         116         40
             5          8          1         114         80
             5          8          3          89         33
             5          8          2          76          0
             5          8          2          76         65
             5          9          3          56         56
             5          9          1          34         34
             5          9          2          11         11
             6          1          1         289         50
             6          4          1         273         10
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             6          5          1         263         30
             6          6          1         233         29
             6          7          1         204         90
             6          3          3         157         34
             6          7          3         123         34
             6          2          2         116         40
             6          8          1         114         80
             6          8          3          89         33
             6          8          2          76          0
             6          8          2          76         65
             6          9          3          56         56
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             6          9          1          34         34
             6          9          2          11         11
             7          1          1         323         50
             7          4          1         273         10
             7          5          1         263         30
             7          6          1         233         29
             7          7          1         204         90
             7          3          3         157         34
             7          7          3         123         34
             7          2          2         116         40
             7          8          1         114         80
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             7          8          3          89         33
             7          8          2          76          0
             7          8          2          76         65
             7          9          3          56         56
             7          9          1          34         34
             7          9          2          11         11
             8          1          1         323         50
             8          4          1         273         10
             8          5          1         263         30
             8          6          1         233         29
             8          7          1         204         90
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             8          3          3         157         34
             8          7          3         123         34
             8          2          2         116         40
             8          8          1         114         80
             8          8          3          89         33
             8          8          2          76          0
             8          8          2          76         65
             8          9          3          56         56
             8          9          1          34         34
             8          9          2          11         11
             9          1          1         323         50
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             9          4          1         273         10
             9          5          1         263         30
             9          6          1         233         29
             9          7          1         204         90
             9          3          3         157         34
             9          7          3         123         34
             9          2          2         116         40
             9          8          1         114         80
             9          8          3          89         33
             9          8          2          76          0
             9          8          2          76         65
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             9          9          3          56         56
             9          9          1          34         34
             9          9          2          11         11
    135 rows selected.
    SQL> SY.

  • How to calculate the area of a large number of polygons in a single query

    Hi forum
    Is it possible to calculate the area of a large number of polygons in a single query using a combination of SDO_AGGR_UNION and SDO_AREA? So far, I have tried doing something similar to this:
    select sdo_geom.sdo_area((
    select sdo_aggr_union (   sdoaggrtype(mg.geoloc, 0.005))
    from mapv_gravsted_00182 mg 
    where mg.dblink = 521 or mg.dblink = 94 or mg.dblink = 38 <many many more....>),
    0.0005) calc_area from dualThe table MAPV_GRAVSTED_00182 contains 2 fields - geoloc (SDO_GEOMETRY) and dblink (Id field) needed for querying specific polygons.
    As far as I can see, I need to first somehow get a single SDO_GEOMETRY object and use this as input for the SDO_AREA function. But I'm not 100% sure, that I'm doing this the right way. This query is very inefficient, and sometimes fails with strange errors like "No more data to read from socket" when executed from SQL Developer. I even tried with the latest JDBC driver from Oracle without much difference.
    Would a better approach be to write some kind of stored procedure, that adds up all the single geometries by adding each call to SDO_AREA on each single geometry object - or what is the best approach?
    Any advice would be appreciated.
    Thanks in advance,
    Jacob

    Hi
    I am now trying to update all my spatial table with SRID's. To do this, I try to drop the spatial index first to recreate it after the update. But for a lot of tables I can't drop the spatial index. Whenever I try to DROP INDEX <spatial index name>, I get this error - anyone know what this means?
    Thanks,
    Jacob
    Error starting at line 2 in command:
    drop index BSSYS.STIER_00182_SX
    Error report:
    SQL Error: ORA-29856: error occurred in the execution of ODCIINDEXDROP routine
    ORA-13249: Error in Spatial index: cannot drop sequence BSSYS.MDRS_1424B$
    ORA-13249: Stmt-Execute Failure: DROP SEQUENCE BSSYS.MDRS_1424B$
    ORA-29400: data cartridge error
    ORA-02289: sequence does not exist
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 27
    29856. 00000 - "error occurred in the execution of ODCIINDEXDROP routine"
    *Cause:    Failed to successfully execute the ODCIIndexDrop routine.
    *Action:   Check to see if the routine has been coded correctly.
    Edit - just found the answer for this in MetaLink note 241003.1. Apparently there is some internal problem when dropping spatial indexes, some objects gets dropped that shouldn't be. Solution is to manually create the sequence it complains it can't drop, then it works... Weird error.

  • Can we show 2 queries in a single query ?

    Hi experts,
    We require an output of a bex query.
    But the output is coming in two different queries.
    Is it possible to show two queries in a single query ?
    Regards,
    Nishuv.

    Hi Praveen,
    We are using bex 3.x. I opened a workbook. in the view toolbar->Toolbars->Control Toolbox.
    I clicked on this. A tool box came in the right side of the sheet.
    The options which we got here are:
    Exit Design mode
    Properties
    View code
    Check box
    Text box
    Command button
    Option button
    List box
    Combo box
    Toogle button spin button
    Scrool bar
    Label
    Image
    More controls
    Tool bar options.
    Here i am not able to see the Analysis grid.
    Is there anything more to be done to get this ?
    Regards,
    Nishuv.

Maybe you are looking for

  • Progress bar for report?

    Hi there, Does anyone have any advice on how to display a progress bar while a report is running (PDF report, web, using Reports 6, OAS)? We have the report output pop up in a new dialog browser window. The window pops up, but depending on the report

  • Flex 2-14 speaker noise, driver problem ?

    hi all, recently bought flex-2 14 then noticed that the speaker is making noise like hisss, or static noise, that happen when playing sound, even when the speaker is set to mute or plugging in a headphone, after the sound had played, the noise gone.

  • Non-blocking server

    Hi there, I've got a problem with the NIO package: I'm trying to make a simple webserver, just to get familiar with SocketChannel, ServerSocketChannel, Selector, Buffer's and so on. My problem is that my server can only receive one single request, th

  • Verify an email has been read

    I recently sent some emails which looked like they had been sent (they were in my sent box and I did not receive any "delivery faiure" notice) only to be told later that the mail had never been recieved. Is there anyway to verify a mail has been reci

  • Where do I save a .atn action file? I don't see the proper folder

    I have W7 computer, with PSE 10.0;  I downloaded an .atn action file and it is now in my "downloads" folder.  Where do I save this .atn file?   I do not see a Workflow Panels\Actions folder in the PSE 10.0\en-US folder.    The directions say to save