Read multiple rows to do aggregation

Hi All
I need some help here:
1. I have to read multiple rows to check where time stamp is same for example rownum (1-3) : *'2013/03/09 10:54:09 PM'*
2. And status is unique for example *(H,L)*
3. And if TIME_STAMP is between TIME_A and TIME_B then flag it as Y else flag it as N.
and if the above condition is not true then
1. Flag the row with ' Y ' where time_stamp is same i.e. : '2013/03/09 10:54:09 PM'
2. And the status is *( ' O ')*
3. the other rows where time_stamp is same, and unique_id is same, and STATUS is either or both ( ' H ' , ' L ' ) flag it as *' N '*
table structure:
CREATE TABLE T2
  TIME_STAMP  DATE,
  STATUS      VARCHAR2(1 BYTE),
  UNIQUE_ID   NUMBER,
  TIME_A      DATE,
  TIME_B      DATE
Insert statement;
SET DEFINE OFF;
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 22:54:09', 'MM/DD/YYYY HH24:MI:SS'), 'H', 6587797, TO_DATE('03/09/2013 23:00:22', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 23:03:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 22:54:09', 'MM/DD/YYYY HH24:MI:SS'), 'L', 6587797, TO_DATE('03/09/2013 22:48:35', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 23:00:22', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 22:54:09', 'MM/DD/YYYY HH24:MI:SS'), 'O', 6587797, TO_DATE('03/09/2013 23:03:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 23:05:54', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 22:54:57', 'MM/DD/YYYY HH24:MI:SS'), 'H', 6587797, TO_DATE('03/09/2013 23:00:22', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 23:03:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 22:54:57', 'MM/DD/YYYY HH24:MI:SS'), 'L', 6587797, TO_DATE('03/09/2013 22:48:35', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 23:00:22', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 22:54:57', 'MM/DD/YYYY HH24:MI:SS'), 'O', 6587797, TO_DATE('03/09/2013 23:03:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 23:05:54', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 18:26:55', 'MM/DD/YYYY HH24:MI:SS'), 'L', 6583483, TO_DATE('03/09/2013 18:15:51', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 18:26:28', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T2
   (TIME_STAMP, STATUS, UNIQUE_ID, TIME_A, TIME_B)
Values
   (TO_DATE('03/09/2013 18:26:55', 'MM/DD/YYYY HH24:MI:SS'), 'O', 6583483, TO_DATE('03/09/2013 18:27:01', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/09/2013 18:33:10', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
Query used:
SELECT time_stamp,
       UPPER (SUBSTR(status,1,1)) as status,
       Unique_ID,
       Time_A,
       Time_B,
       CASE
            WHEN time_stamp BETWEEN Time_A AND Time_B
          THEN
               'Y'
          ELSE
               'N'
         END   as flag
  FROM t2;
the query provided above doesn't work with these rows:
TIME_STAMP,                STATUS,     UNIQUE_ID,      TIME_A,                             TIME_B,                                    FLAG
2013/03/09 6:26:55 PM,   L,              6583483,          2013/03/09 6:15:51 PM,     2013/03/09 6:26:28 PM,              N
2013/03/09 6:26:55 PM,   O,              6583483,          2013/03/09 6:27:01 PM,      2013/03/09 6:33:10 PM,             N
because here where time_stamp is same and time_stamp is not between time_a and time_b therefore it should be flagged Y on the row where status is *' O '*
Edited by: 855161 on Apr 10, 2013 7:36 AM

Hi,
Sorry, it's unclear what you want.
855161 wrote:
Hi All
I need some help here:
1. I have to read multiple rows to check where time stamp is same for example rownum (1-3) : *'2013/03/09 10:54:09 PM'*
2. And status is unique for example *(H,L)*
3. And if TIME_STAMP is between TIME_A and TIME_B then flag it as Y else flag it as N.
and if the above condition is not true then
1. Flag the row with ' Y ' where time_stamp is same i.e. : '2013/03/09 10:54:09 PM'
2. And the status is *( ' O ')*
3. the other rows where time_stamp is same, and unique_id is same, and STATUS is either or both ( ' H ' , ' L ' ) flag it as *' N '*
the query provided above doesn't work with these rows:
TIME_STAMP,                STATUS,     UNIQUE_ID,      TIME_A,                             TIME_B,                                    FLAG
2013/03/09 6:26:55 PM,   L,              6583483,          2013/03/09 6:15:51 PM,     2013/03/09 6:26:28 PM,              N
2013/03/09 6:26:55 PM,   O,              6583483,          2013/03/09 6:27:01 PM,      2013/03/09 6:33:10 PM,             Nbecause here where time_stamp is same and time_stamp is not between time_a and time_b therefore it should be flagged Y on the row where status is *' O '*What are the complet, correct results you want from thissample data?
Are they the same as what you are currently getting, except that the 2 rows above should have flag = 'O'?
Why should the row that has status='L' get flag='O'?
Why don't the other rows that currently have status='O' and flag='N' need to be changed?
To see if there are other rows with the same time_stamp, you can use the analytic COUNT function, like this:
SELECT time_stamp,
       UPPER (SUBSTR(status,1,1)) as status,
       Unique_ID,
       Time_A,
       Time_B,
       CASE
            WHEN time_stamp BETWEEN Time_A AND Time_B
                THEN
                    'Y'
            WHEN  COUNT (*) OVER (PARTITION BY  time_stamp) > 1
         AND       UPPER (SUBSTR (status, 1, 1)) = 'O'
             THEN
              'O'
                ELSE
                    'N'
         END   as flag
  FROM t2
ORDER BY  time_stamp
,            status
;The results that this produces are :
`                        UNIQUE
TIME_STAMP           S      _ID TIME_A               TIME_B               F
09-Mar-2013 18:26:55 L  6583483 09-Mar-2013 18:15:51 09-Mar-2013 18:26:28 N
09-Mar-2013 18:26:55 O  6583483 09-Mar-2013 18:27:01 09-Mar-2013 18:33:10 O
09-Mar-2013 22:54:09 H  6587797 09-Mar-2013 23:00:22 09-Mar-2013 23:03:00 N
09-Mar-2013 22:54:09 L  6587797 09-Mar-2013 22:48:35 09-Mar-2013 23:00:22 Y
09-Mar-2013 22:54:09 O  6587797 09-Mar-2013 23:03:00 09-Mar-2013 23:05:54 O
09-Mar-2013 22:54:57 H  6587797 09-Mar-2013 23:00:22 09-Mar-2013 23:03:00 N
09-Mar-2013 22:54:57 L  6587797 09-Mar-2013 22:48:35 09-Mar-2013 23:00:22 Y
09-Mar-2013 22:54:57 O  6587797 09-Mar-2013 23:03:00 09-Mar-2013 23:05:54 OI don't think this is what you wat, but I'm not sure.
Can you explain, in a different way than before, what flag is supposed to show? What role (if any) does the so-called unique_id play in this problem?

Similar Messages

  • Read multiple rows in a single time

    Dear All,
    Does anyone has idea on how to read using java to read 10000 rows and write it to a file
    code:
    FileReader fr =
    new FileReader(fileDir + "/" + orgFiles);
    BufferedReader br = new BufferedReader(fr);
    String record = br.readLine();
    while (record != null) {
    String[] afterSplit = record.split(",");
    System.out.println("recordLength : " +afterSplit.length);
    for (int p = 0; p < 1; p++) {
    test= afterSplit[0];
    test1= afterSplit[1];
    test1 = afterSplit[2];
    it reads a single line in a test file and then write it to another file.i have 100000 rows in that file is there any possibility to read 100000 record in a time (ie) instead of record=br.readline and then split that any other way to read all the rows and assign it to afterSplit ?

    Hi kayaman,
    Thanks for ur reply.if there are 100000 records in the text file
    For Example,
    bsc,bsc1,bsc2,bsc3
    bsc4,bsc5,bsc6,bsc7
    bsc8,bsc9,bsc10,bsc11
    it reads bsc,bsc1,bsc2,bsc3 and then write it to some file
    is there any possibility to read all
    bsc,bsc1,bsc2,bsc3
    bsc4,bsc5,bsc6,bsc7
    bsc8,bsc9,bsc10,bsc11
    then write there thses 3 in a single time.

  • Problem in creating UDF to read multiple rows of IDOC segment

    Hi Experts,
    I am working on IDOC to File scenario, in message mapping i have to read segment of idoc (occurence of this segment is 0..4) and check the key of this segment and accordingly pass the value. I am creating a UDF to send the data in target field
    My logic in UDF is as follows
    if id = BB and payment = V
    return variable1
    else
    return variable2
    this logic is not working
    Note: The id BB is in second line of the segment and first line of the segment has id BA.
    Please help me to send me the correct logic.
    Regards,
    Shradha

    Hi Amit,
    My source and target structure are as follows
    My requirement is if FIIQUALI = BB than return D_1131 = 25 else D_1131= 20.
    +Source IDOC structure:+
    - <E1IDB02 SEGMENT="1">
      <FIIQUALI>BA</FIIQUALI>
      <FIIBKENN>206151</FIIBKENN>
      <FIIBKCDE>013</FIIBKCDE>
      <FIIBKNAM>BARCLAYS BANK PLC</FIIBKNAM>
      <FIIBKORT>NORTHAMPTON NN1 4YD</FIIBKORT>
      <FIIBLAND>GB</FIIBLAND>
      <FIIKONTO>18150680</FIIKONTO>
      <FIIKWAER>USD</FIIKWAER>
      <CTABNAME>Norman Jackson</CTABNAME>
      <FIIBRANCH>NTHAMPTON WELLINBOROUGH RD</FIIBRANCH>
      </E1IDB02>
    - <E1IDB02 SEGMENT="1">
      <FIIQUALI>BB</FIIQUALI>
      <FIIBKENN>BOFAUS3NWDC</FIIBKENN>
      <FIIBKCDE>002</FIIBKCDE>
      <FIIBKUKN>054001204</FIIBKUKN>
      <FIIBKUCD>003</FIIBKUCD>
      <FIIBKNAM>BOFA</FIIBKNAM>
      <FIIBKORT>WASHINGTON DC</FIIBKORT>
      <FIIBLAND>US</FIIBLAND>
      <FIIKONTO>1920901042</FIIKONTO>
      <FIIKNAME>VERISIGN INC</FIIKNAME>
      </E1IDB02>
    Target File structure:
    - <G_SSG2>
    - <S_FII>
      <D_3035>OR</D_3035>
    - <C_C078>
      <D_3194>18150680</D_3194>
      </C_C078>
    - <C_C088>
      <D_1131>25</D_1131>
      <D_3434>206151</D_3434>
      <D_1131_2>154</D_1131_2>
      <D_3055_2>133</D_3055_2>
      <D_3432>BARCLAYS BANK PLC</D_3432>
      <D_3436>NORTHAMPTON NN1 4YD</D_3436>
      </C_C088>
      </S_FII>
      </G_SSG2>
    - <G_SSG2>
    - <S_FII>
      <D_3035>BF</D_3035>
    - <C_C078>
      <D_3194>1920901042</D_3194>
      <D_3192>VERISIGN INC</D_3192>
      </C_C078>
    - <C_C088>
      <D_1131>20</D_1131>
      <D_3434>BOFAUS3NWDC</D_3434>
      <D_1131_2>154</D_1131_2>
      <D_3055_2>133</D_3055_2>
      <D_3432>BOFA</D_3432>
      <D_3436>WASHINGTON DC</D_3436>
      </C_C088>
      </S_FII>
      </G_SSG2>
    Regards,
    Shradha

  • Reading each value from spreadshee​t file with delay (multiple rows and columns)

    Hi,
    a) I want to read EACH VALUE from a spreadsheet file having multiple rows and columns WITH DELAY. I am attaching my VI and sample datalog file for reference (tempsensor.txt).I need to do so because as soon as I read put ON the Sensor button on front panel, LV reads all the values at one go. I need the values for each temperature to be displayed after a delay.
    b) Secondly, I would like to read another file containing the state of four antennas (deployed:1; undeployed:0). I am logging state of each antenna in each column of the file(magnet.txt) I need to have four LEDS on front panel to display state of the antennas. I dont know what I have done for antennas in my VI is right or wrong. I guess thats rhe wrong way to approach the problem. Please help!!!(column1: Antenna1 state ; Column2:Antenna2 state.. and so..on..)
    Any help would be greatly appreciated!!
    Thanks in advance,
    Ratnesh
    FYI: The first column in my datalog file represents timestamp(number of seconds elapsed), second column: reading for temperature sensor 1, third column: reading for temperature senosr 2, and so on. I am using approx. 11 temperature sensors.
    Also, I have generated the log files for the reference purpose only. They do not represent the actual values. They are far away from actual values.
    Attachments:
    01032005.zip ‏30 KB

    Look at this modified version of your VI. After looking at it, I determined that a shift reggister was not required in this case.
    Lynn
    Attachments:
    MultiSensors.2.vi ‏85 KB

  • How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    CVI Comes with a sample project that explains how to read/write to a Excel file: choose "Explore examples..." in CVI welcome page and navigate to <cviSampleDir>\activex\excel folder where you can load excel2000dem.prj.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Depicting multiple rows' data in one row

    Hi All,
    Pls. check the below query:
    select manager_id mg_id, employee_id emp_id, last_name name from employees
    where manager_id = '100'
    and DEPARTMENT_ID = '80'if i run the following query, then o/p comes row wise; like below:
           mg_id           emp_id            name
           100             145                     Russell
           100             146                     Partners
           100             147                     Errazuriz
           100             148                     Cambrault
           100             149                     Zlotkeybut if i want the o/p like below; i.e; under manager # 100, all employees' emp_id and name should come in only ONE row NOT in multiple rows:
    mg_id                   emp_id     name          emp_id       name       emp_id     name         emp_id     name                emp_id         name
    100                             145             Russell     146       Partners        147     Errazuriz       148              Cambrault        149        Zlotkeypls. help me to sort out the above sought o/p.
    kindly tell me if there is any posting guidelines (except "Plain Text Help" on the right side) in this forum. i tried a lot to post above two o/p in easily readable format, but couldn't do that.
    Edited by: Shariful on Sep 20, 2009 4:28 AM
    Edited by: Shariful on Sep 20, 2009 4:29 AM

    Hi,
    Shariful wrote:
    Hi All,
    Pls. check the below query:
    select manager_id mg_id, employee_id emp_id, last_name name from employees
    where manager_id = '100'
    and DEPARTMENT_ID = '80'
    if i run the following query, then o/p comes row wise; like below:
    mg_id           emp_id            name
    100     145     Russell
    100     146     Partners
    100     147     Errazuriz
    100     148     Cambrault
    100     149     Zlotkey
    but if i want the o/p like below; i.e; under manager # 100, all employees' emp_id and name should come in only ONE row NOT in multiple rows:
    mg_id                   emp_id     name          emp_id       name       emp_id     name         emp_id     name                emp_id         name
    100     145     Russell     146     Partners     147     Errazuriz     148     Cambrault     149     ZlotkeyIf you want all the emp_ids and names concatenated into one big VARCHAR2 column, that's called String Aggregation
    [AskTom.oracle.com|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402] shows several different ways to do it.
    You can format that one big column so that it looks like separate columns.
    If you want each emp_id and name in its own column, that's called Pivoting .
    Look up "pivot" for various techniques. If you do not know exactly how many rows were in the original query (and therefore how many columns you'll need in the output), then it will require Dynamic SQL , which can be complicated.
    Unfortunately, when you do search for "pivot", mlost of the hits will be things like "Search for pivot and you'll get lots of examples".
    Re: Help for a query to add columns is one that actually has some information. It was a question very much like yours.
    kindly tell me if there is any posting guidelines (except "Plain Text Help" on the right side) in this forum. i tried a lot to post above two o/p and query in easily readable format, but couldn't do that.Type these 6 characters:
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Collecting data from multiple rows into one column

    I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
    PL/SQL Release 10.2.0.5.0 - Production
    "CORE     10.2.0.5.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
         CREATE TABLE "SKIP"."INGREDIENTS"
       (     "INGRED_ID" NUMBER,
         "INGRED_NAME" VARCHAR2(20 BYTE),
         "STORES" VARCHAR2(20 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.INGREDIENTS
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
      CREATE TABLE "SKIP"."PRETZELS"
       (     "PRETZEL_ID" NUMBER,
         "PRETZEL_NAME" VARCHAR2(20 BYTE),
         "PRETZEL_DESC" VARCHAR2(100 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.PRETZELS
    Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
    Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
      CREATE TABLE "SKIP"."INGRED_XREF"
       (     "PRETZEL_ID" NUMBER,
         "INGRED_ID" NUMBER
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.INGRED_XREF
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
    --  Constraints for Table INGRED_XREF
      ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
      ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
    {code}
    Desired output (note how the ingredients are all listed in one column, separated by commas):
    {code}
    PRETZEL_ID PRETZEL_NAME     PRETZEL_DESC                        INGREDIENTS
    1          CLASSIC          Classic knot pretzel                SEA SALT, TABLE SALT, YEAST
    2          THICK STICK      Straight pretzel, abt 1/2" in dia   TABLE_SALT, FLOUR, BEER

    See the FAQ : {message:id=9360005}
    Especially links concerning string aggregation.

  • Adding up Downloads excessively due to multiple rows in Tabular

    Hi All ,
    We have fact table table which has data for Products that are taken down from the  App Store ,due to different reasons like App has risky key words , App has adult content etc  ...  We get the data from the staging table as below 
    As the "reasonForTakeDown" column is having comma separated string , now we need to split this reason in to multiple rows taking Comma as the delimiter. So the first ,second and Third ProductGUIDs  have to repeated multiple
    times to each "reasonForTakeDown" as shown below 
    So in the above example if get the sum(Downloads) for the productKey 1 , then value is 300 where as the Staging value is 100.Same as with the productKey 2 , Sum(Downloads) from the fact table is 150 where as the Staging value is 50 and same case with ProductKey
    3 as well . Downloads and Revenue numbers are getting inflated due to multiple rows 
    I have a Tabular basing on the above fact table and having measures as "Downloads" and "Revenue" which are set to aggregation type as "SUM".  For the products like 1,2 and 3 we are
    getting inflated numbers from cube when compared to Staging table due to the column ReasonForRemovalkey.
    Now the problem is avoid the excess counting of downloads and Revenue by keeping multiple rows in fact table to satisfy reasonForRemovalKey Scenario . Can you help me out in writing an DAX so that anytime i will get the
    correct number of downloads and revenue which are matching with staging table.
    Approaches tried:
    1)  Tried changing the aggregation type from SUM to Avg , but this aggregation type would give avg of downloads when the user selects multiple products. Suppose if the user selects ProductKey 1 & 2  then Avg downloads measure would be (100+100+100+50+50+50)
    / 6  = 75 , where as the original downloads sum is  100+50  = 150 .So Avg aggregation wont work for me.
    2) I cannot divide the value of  downloads/NetRevenue for a product with the count of rows for that product in fact table.So that Sum(Downloads) and Sum(NetRevenue) would give me correct values.I cannot do this because , if want to get the downloads
    for a TCR and a product then i would download measure share of that TCR but not the total downloads.
    Hope i explained my scenario well. Thanks in advance

    Spliting the message as it supports only two images per message .
    Contd : 
    Now the scenarios that needs to satisfied as below :
    If user selects a product then we should get only the latest download and revenue out of the above multiple rows for a product from the tabular cube .i.e. as shown in the below snip  
    Suppose if the user selects any other column instead of Product from the tabular cube , suppose if the user selects a date as a dimension on the row labels and Downloads ,Revenue as the measure from the Tabular cube , then it should only the max downloads
    and Revenue for a product. i.e 
    Now the same case as date with Requester also .If user selects requester then we should count only the downloads and revenue only once i.e. is the max downloads and revenue for a product and a requestor as shown in the below table  
    RequestorKey Downloads Revenue 
    1                    100             50
    2                    150             40
    3                    105             55
    Hope i explained now clearly the scenarios.Thanks  you once again for your time 

  • How to convert multiple rows into colmun data?

    Hi all
    ODI has fuction that covert multiple rows form a file into colmun data?
    Source:customer.txt
    001,Scott
    001,Man
    001,23
    002,Lincon
    002,Man
    002,21
    objective Target:customer
    ID Name Sex Age
    001 Scott Man 23
    002 Lincon Man 21
    If there is no this fuction,how can I do this in ODI?
    Thanks in advance.
    Agui

    Hi, Sanjeev,
    What you requested is called String Aggregation.
    Like most other things, the best way to do it depends on your version of Oracle.
    The following site shows several different ways to do string aggregation:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php'
    The user-defined function (often called STRAGG) that Charles mentioned is my favorite, in versions between 9.1 and 11.1.

  • Query for Multiple Rows as XML

    Ok I've seen this topic in the forums, but have failed to get this to work within my process. Basically I have a process that has a user fill out a form, and upon submittal the form writes it's information to a database (via a data connection within the form that invokes a separate process upon submittal.), once this is done the main process is invoked and it's first step is to query that same database and bring back the data in a lower (now exposed) portion of the form that contains certain fields that track the issue history. The query brings back the xml document and I store it in an xml variable (xml_output). I then take this information and use the Set Value object to assign the returned nodes values to the location fields in the form. This works if the query returns only one row. But once the form is moved beyond the initial Task Assignment, (first user), and query returns more than just one row, the added nodes to not show up on the form, i.e I still just get information about the first row in my form. From what I've read the form should be able to recognize the xpath expression, and bring back all the nodes, by in a sense using instance manager to create an instance for each node on the form. My question is how can I get this to work. Jasmin if your still out there... Help!
    Also We're using Adobe LiveCycle ES 8.0
    created the process using Workbench
    the form was reader enabled and saved as a dynamic PDF.
    Thanks
    Mike

    Ok have done the binding of the schema to the form, and I'm getting the information to flow as it's supposed to.  The problem I'm having now, (I know I'm having a bunch.) is that once I've placed the form into my process, and I use the set value operation to pre-fill information I get the form to flow, but the rest of the information that was previously filled in is blank.  So I have checked the variable and nothing wrong there.  It appears the problem is how I'm using the set value operation.  If I don't use the set value operation, the form retains it's information.  And if I use the set value by trying to set the subform value, the form retains it's information, but no pre-fill.  I'm going to try to be a little more detailed here.  The xml that is returned looks like this:
            0016-03-30
            Mike
            Public Works
            alone in the dark
            Type sleep
            -1
            Council
            FYI
            Important
    Flowed and positioned are actual subforms on the form that have their properties set as their names indicates.  The entire path is /form1/Page1/flowed/positioned .  The way I was able to get the form to flow correctly upon the injection of this xml data, was to bind the subforms in the form in this manner, positioned[*].  Designer didn't place the [*] for me so I had to do this myself.  But once I previewed the document, the form pre-populated and created the necessary number of subforms and placed information into the fields correctly.
    Now on the process side, I have created an xfaform variable that stores the form (bound to xsd.)  information, and another xml variable that stores the query return that looks like the xml listed above (has an xsd associated with it for navigating xpath).  My first operation performs the query (JDBC- Query Multiple Rows as XML) and stores it into the xml variable.  The next step of the process is the Set Value operation which is supposed to inject the xml data retrieved from the query into the form.  Initially I tried the an xpath similar to the following:
    /process_data/object/data/form1/page1/flowed/positioned = /xml_data/flowed/positioned.
    No dice.  On this one the form retains the information filled out by the user (didn't explain this earlier, the form is filled out first, and upon submittal the process starts.), but doesn't pre-populate the bottom part of the form.  Next I tried the following xpath:
    /process_data/object/data/form1/page1/flowed = /xml_data/flowed/positioned.
    This time it retained the form information which was filed in by the user, but the bottom part is becomes hidden!  Didn't understand this.  But I started to kinda think that I had to navigate he xpath in order to correctly inject the xml into the form.  That being said my next attempt was:
    /process_data/object/data/form1/page1 = /xml_data
    My thinking was that if on location, I stop at page1, the xml in the variable will allow it to navigate correctly through the form.  Well it worked, but too well.  The top part of the form is blank, but the bottom portion is pre-populated correctly.  Now I'm stuck.  Not sure how to get the rest of the information in the form.  I thought about creating variables form each of the fields and then re-populating them after the injection of xml, but that didn't seem practical.  I'm almost positive it's something I'm not doing correctly with xpath.  Anyway, thanks for all your help on this.
    Mike

  • Multiple Rows Update / Refresh Toplink Query when database trigger involved

    Hi everybody!
    I have two easy troubles for you; the platform is the same as the SRDemo Toplink version.
    1.     Multiple Rows Update: I want to update with mergeEntity method, multiple rows for an isolated table; that method receives a parameter that I try to bind with the iterator "dataProvider" but it only merges the first row, not all, any other combination returns an error.
    What I want to do is to have a form (like tabular forms in Apex) that lets me update multiple rows in a single page. ¿May anyone tell me how to do it?
    2.     Refresh Toplink Named Query: I have a list on a page with two columns. From another page, a button does an action that fires a database trigger that updates one of the columns on the list´s page. When I go back to the list, it is not updated; however, the CacheResults´s property is set to false on the iterator.
    Thanks in advance,
    Alejandro T

    I didn't use it (yet), but - you might take a look. You'll find a [url http://www.oracle.com/technetwork/developer-tools/apex/application-express/apex-plug-ins-182042.html]Timer plug-in on this page. It is a dynamic action which allows you to periodically fire other dynamic actions in the browser. For example use the timer to refresh a region every five minutes. You can perform any dynamic action you want using this infrastructure.So I was thinking: you might use it to run a dynamic action which would check whether something changed in that table (I suppose you'll know the way) (for example, a database trigger might set a flag in some table, timestamp or similar), and - if you find that something really changed - refresh the page.
    As I said, I never used it so that's pure theory. Someone else might know better, though.

  • Multiple rows insertion - need help

    Hello all,
    I need to insert multiple rows in a table with a single query and the number of rows is 269470.
    There are 3 columns in the table. One of the columns is determined by another sub query which returns multilple(269470) rows and the other 2 columns remain same for all.
    I came up with the following query but need a loop to make it run multiple time(269470 times).
    insert into EMLUSRRECV
    (user_id, storeent_id, receiveml)
    values
    ((select user_id from users where user_id not in (select distinct user_id from EMLUSRRECV) and CURR = 'USD' and rownum = 1), 11154, 1);
    Thanks in advance.
    Edited by: 924585 on Feb 20, 2013 7:19 PM

    924585 wrote:
    Hello all,
    I need to insert multiple rows in a table with a single query and the number of rows is 269470.
    There are 3 columns in the table. One of the columns is determined by another sub query which returns multilple(269470) rows and the other 2 columns remain same for all.
    I came up with the following query but need a loop to make it run multiple time(269470 times).
    insert into EMLUSRRECV
    (user_id, storeent_id, receiveml)
    values
    ((select user_id from users where user_id not in (select distinct user_id from EMLUSRRECV) and CURR = 'USD' and rownum = 1), 11154, 1);
    Thanks in advance.
    Edited by: 924585 on Feb 20, 2013 7:19 PMwhy not just:
    insert into emlusrrecv
    select user_id, 11154, 1
      from  users
    where user_id not in (select user_id from EMLUSRRECV)
    and CURR = 'USD' and rownum = 1)

  • The simplest way for plsql procedure to return multiple rows

    Hi,
    What is the simplest way for plsql procedure to return multiple rows (records). There are many combination of ways to do it but I am looking for a solution that is appropriate for plsql beginners. Many solutions use cursors, cursor variables, collections and more that kind of things that are complex on the face of it. Is it somehow possible to achieve the same with less effort?
    Sample query would be: SELECT * FROM EMPLOYEES;
    I want to use returned rows in APEX to compose APEX SQL(in that context plsql) report.
    It is enough to use just SELECT * FROM EMPLOYEES query in APEX but I want to use plsql procedure for that.
    Thank you!

    Hi,
    It depends :-).
    With +...that is appropriate for plsql beginners...+ in mind... it still depends!
    The list of techniques (ref cursors, cursor variables, collections, arrays, using explict SQL) you have referenced in your post can be made to work. but...
    +Is it somehow possible to achieve the same with less effort?+ Less effort : That needs to be defined (measured). Especially in the context of pl/sql beginners (who is a beginner?) .
    What is the level of "programming experience" ?
    What is the level of understanding of "Relational Result set" as processible in Oracle?
    If you are looking for
    Process_the_set_of rows_in APEX () kind of capabilitywhich "abstracts/hides" relation database from developers when working on relation database, it may not be the best approach (at least strategically). Because I believe it already is abstracted enough.
    I find REF CUROSOR most effective for such use, when the "begginer" has basic understanding of processing SQL result set .
    So in a nut shell, the techniques (that you already are familiar with) are the tools available. I am not aware of any alternative tools (in pure Oracle) that will simplify / hide basics from develpers.
    vr,
    Sudhakar B.

  • Help me with returing multiple rows - Query

    I am trying to return multiple rows and i need help with my query.
    and most important of all one of the requirement is the following:
    SERVICE LEVEL has categories Sergeant, Bonus I, All Deputies, Deputy Bailiff, Deputy Lockup, Deputy Bailiff Security, Custody Assistant,
    Security Officer, Security Assistant, Security Officer and Security Assistant, Private Security, ALL, All Sworn)
    Note: Service Level “All Deputies” includes Deputy Bailiff, Deputy Bailiff Security and Deputy Lockup
    *“All Sworn”: includes Sergeant, Bonus I, All Deputies, Deputy Bailiff, Deputy Lockup, Deputy Bailiff Security*
    //this code doesn't work cuz  case- when statement return only one row. but it works for singles such as 'Sergeant'
    select *
    from in_service
    where rank IN (CASE TRIM(UPPER(:SL))
                    WHEN 'ALL DEPUTIES' THEN
                      (SELECT DISTINCT RANK FROM IN_SERVICE
                       WHERE UPPER(RANK) LIKE 'DEPUTY%')
                    WHEN 'ALL SWORN' THEN
                   (SELECT DISTINCT RANK FROM IN_SERVICE
                   WHERE UPPER(RANK) LIKE 'DEPUTY%' OR
                   UPPER(RANK) = 'SERGEANT' OR
                   UPPER(RANK) = 'BONUS 1')
                    WHEN 'ALL' THEN
                   (SELECT DISTINCT RANK FROM IN_SERVICE
                   WHERE UPPER(RANK) LIKE 'DEPUTY%' OR
                   UPPER(RANK) = 'SERGEANT' OR
                    UPPER(RANK) = 'BONUS 1' OR
                   UPPER(RANK) LIKE 'SECURITY%' OR
                   UPPER(RANK) = 'CUSTODY ASSISTANT' OR
                    UPPER(RANK) = 'PRIVATE SECURITY') 
                    end )   I was able to get multiple rows for 'ALL' and specified category like 'Sergeant' or 'Bonus I' from the code below, but NOT for 'All Deputies' for example which includes Deputy Bailiff, Deputy Bailiff Security and Deputy Lockup. I know CASE, WHEN does NOT return multiple rows, but i am having problems writing the query to make it work for all categories as the requirements mentioned above.
    WHERE RANK IN (SELECT RANK FROM (SELECT RANK, 'ALL' ALL_SERVICE
                                            FROM IN_SERVICE
                                            UNION ALL
                                            SELECT RANK, RANK
                                            FROM IN_SERVICE) WHERE ALL_SERVICE = :SL)Please help.
    Thanks in advance

    If you define your service_level as a table then it will be much easier.
    with service_level
    as
    select 'ALL' parent_lvl, 'Sergeant' srv_lvl from dual union all
    select 'ALL', 'Bonus I' from dual union all
    select 'ALL', 'Deputy Bailiff' from dual union all
    select 'ALL', 'Deputy Lockup' from dual union all
    select 'ALL', 'Deputy Bailiff Security' from dual union all
    select 'ALL', 'Custody Assistant' from dual union all
    select 'ALL', 'Security Officer' from dual union all
    select 'ALL', 'Security Assistant' from dual union all
    select 'ALL', 'Security Officer and Security Assistant' from dual union all
    select 'ALL', 'Private Security' from dual union all
    select 'All Deputies', 'Deputy Bailiff' srv_lvl from dual union all
    select 'All Deputies', 'Deputy Bailiff Security' from dual union all
    select 'All Deputies', 'Deputy Lockup' from dual union all
    select 'All Sworn', 'Sergeant' srv_lvl from dual union all
    select 'All Sworn','Bonus I' from dual union all
    select 'All Sworn','All Deputies' from dual union all
    select 'All Sworn','Deputy Bailiff' from dual union all
    select 'All Sworn','Deputy Lockup' from dual union all
    select 'All Sworn','Deputy Bailiff Security' from dual
    select *
      from in_service
    where rank IN (
              select srv_lvl
                from service_level
               where upper(parent_lvl) = upper(:SL)
                  or upper(srv_lvl) = upper(:SL)
                   )

  • Help :add multiple rows from Resultset to ArrayList ?

    My query returns one column and multiple rows. In Java code , I am trying to get this data in array or arraylist through ResultSet
    ex:
    item_num
    p001
    p002
    p003
    when I print, it only gets the item in the first row.
    ArrayList myArrayList = new ArrayList();
    resultset = preparedstatement.executeQuery();
    if (resultset.next())
    myArrayList.add(new String(resultset.getString("item_num")));
    Print:
    for (int j = 0 ; j < myArrayList.size() ; j++ )
    System.out.println((String)myArrayList.get(j)); --this prints only the first item.
    can someone assist ?

    changing if to while fixed it.

Maybe you are looking for

  • Can't access User type using Synonyms/Grant

    Hi, We have a Stored Proc and it accepts a usertype. We are sending info from Java using JDBC and trying to get the results back. If I use the owner of the schema for connection it works fine. If I use a different schema user which has synonyms and g

  • How to remove background on image

    Hi I would like to make the background on the attached image white and to manipulate the silver jewellery on the image attached so that it shows up clearly against the white. I've tried all sorts of things but found that either the image blends into

  • Alerts with variables from the messages payload without BPM?

    Hi, experts: Is it possible to define a alert category with variables from the messages payload(for example:order_id ) without BPM? Regards Yu Ming

  • ESS child iviews are not coming in PCD.

    Dear All. We are working on ESS Implementation and we installed Netviewer 7.01 sp6. Our ECC version is 5.0. We deployed SAP_ESS  100 SP21                        SAP_MSS  100 SP21                        SAPPCUI_GP  100 SP21                        BP_E

  • I have an issue with my Macbook 13"

    Hello. I have recently replaced the hard drive in my Macbook 13" (Mid-2009 Model), and it currently does not have an OS on it. I had purchased OS X Lion from the appstore on my iMac, and made a bootable USB with it, and when I booted it in my mac (He