Need Help with complex query and computing values

I have an issue trying to combine data from several tables. I need help trying to compute the "Total Hours", "Max Pressure" ,"Average Pressure" while displaying the "Manufacturer",
"Part Type" , "Serial Number", "District", "Status","Truck Type",and "truck number" for a certain Part on all Trucks. I need to be able check and see if the serial number was on
a particular job and calculate the hours of that serial number if it was on that job and the jobdate falls between the install date and removal date. Ive tried but keep getting either
repeating rows, total hrs of the truck instead of the serial number. Ive considered doing a pivot to display it but have been having trouble putting it together.
table 1
(*records of parts*)
 Contains  serial number,truck number, part type, part number, install date, removal date, status
table 2
(*records of Jobs*)
contains Jobnumber, JobStartdate, Max pressure, average pressure, and Totalhrs
table 3
(records related to jobs and trucks)
contains jobnumber, district , and truck numbers
Table 4
(records of manufacturers and part numbers)
contains partnumber, manufacturer name, and truck type
I would like to get it to show like below
SerialNo   PrtType       
MFG      TruckNo  
 TrkType    TtlHrs 
   MaxPr   AvgPr 
  Status    
Dst
AB345     1200series  
NGK        2G34        
Boss X       400     10,000 
 9500  NonOp    
NE
Thanks in advance

Hope this helps
Note: (Date of Mar 1 2014 was just extended to a further date so the system would know that its still operating when calculating current hours)
Table 1
SerialNo    TruckNo  InstallDate RemovalDate      Status       PartNo      PartType
BJ1002       F917   2013-09-17   2014-03-01   Oper         L871235       BJ 3000 GL
CWS1002   F104   2012-11-21   2013-03-29   NonOper   L76088-450   CWS 2000
CWS1003   F104   2013-04-24   2013-08-01   NonOper   L76088-450   CWS 2000
CWS1005   F187   2012-11-21   2013-04-04   NonOper   L76088-450   CWS 2000
CWS1006   F187   2013-04-24   2013-06-30   NonOper   L76088-450   CWS 2000
CWS1007   F187   2013-06-30   2013-03-01   Oper         L76088-450   CWS 2000
CWS1009   2F60   2013-05-05   2013-03-01   Oper         L76088-450   CWS 2000
CWS1011   F809   2013-05-28   2013-08-28   NonOper   L76088-400   CWS 2000
CWS1013   F990   2013-06-11   2013-10-29   NonOper   L76088-450   CWS 2000
CWS1015   F783   2013-06-28   2013-03-01   Oper         L76088-450   CWS 2000
Table 2
JobNumber    Date                 District         PrAvTreat PrMaxTr TotalHrs
553811287    2012-01-19    Fairmount    7337        8319     1.53
652110088    2012-08-20    San Antonio  6340       7075      0.47
652110090    2012-08-21    San Antonio  6134       7131      0.62
652110091    2012-08-22    San Antonio  6180       2950      0.58
652110092    2012-08-23    San Antonio  5959       6789      0.64
652110093    2012-08-23    San Antonio  6165       7466      0.62
Table 3
TruckNo District    JobNumber
1F01      Odessa   10011012329
1F01      Odessa   10011012333
1F01      Odessa   10011014831
1F01      Odessa   10011014834
1F01      Odessa   10011012332
1F01      Odessa   10011012328
1F01      Odessa   10011014829
Table 4
PartNumber    Manufacturer  TruckType
L322020-2     Jimmy Dean   Ford T
L322738-2     Lucas             Ford T
L47869-1       Jimmy Dean   Ford T
L76070-650   NGK               Ford T   
Sam Howard

Similar Messages

  • Need Help with complex query for productio database

    Hello again,
    i need your help again, for an query how Shows me how long every production step takes per Order.
    See sample data and what i expect.
    Thank you all for your help.
    We use Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    Here the sample data tables:
    CREATE      TABLE      TABLE_2
    (     "ORDER_NR"      VARCHAR2 (12)
    ,      "PRIORITY"      VARCHAR2 (2)
    ,      "WO_STEP"      VARCHAR2 (1)
    ,      "STEP_DATE"      DATE
    CREATE      TABLE      TABLE_1
    (     "ORDER_NR"           VARCHAR2     (12) PRIMARY KEY
    ,      "PRIORITY"           VARCHAR2      (2)
    ,      "CREATE_DATE"      DATE
    ,     "ACT_STEP"          VARCHAR2     (2)
    ,     "STEP_DATE"          DATE
    ,     "EMPLOYEE"          VARCHAR2     (5)
    ,     "DESCRIPTION"     VARCHAR2     (20)
    INSERT      INTO      TABLE_1      (ORDER_NR,               PRIORITY,      CREATE_DATE,                                                        ACT_STEP,     STEP_DATE,                                                            EMPLOYEE,     DESCRIPTION)
                        VALUES           ('1KKA1T205634',     '12',          TO_DATE('10-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'),     'U',          TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'),     'W0010',     'CLEAN HOUSE');
    INSERT      INTO      TABLE_1      (ORDER_NR,               PRIORITY,     CREATE_DATE,                                                        ACT_STEP,     STEP_DATE,                                                            EMPLOYEE,     DESCRIPTION)
                        VALUES           ('1KKA1Z300612',     '12',          TO_DATE('08-FEB-13 14:00:00','DD-MON-RR HH24:MI:SS'),     'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'),     'K0052',     'REPAIR CAR');
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'A',          TO_DATE('12-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'K',          TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'K',          TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'C',          TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'B',          TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'E',          TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'S',          TO_DATE('21-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'R',          TO_DATE('21-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'U',          TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'A',          TO_DATE('12-FEB-13 13:52:42','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'K',          TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'K',          TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'C',          TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'B',          TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'E',          TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    COMMIT;And here is what i expect from my query:
    SYSDATE     28.Feb.13 14:00                                                                                     
    ORDER_NR     PRIORITYCREATE_DATE     STATUS     STATUS_DATE     DESCRIPTION     AGE_1     AGE_2     WAITNG     STEP_A     STEP_B     STEP_C     STEP_5     STEP_K     STEP_E     STEP_F     STEP_S     STEP_R     
    1KKA1T205634     12     10.Feb.13 10:00     U     28.Feb.13 12:00     CLEAN HOUSE     18,083     8,833     2,125     0,833     4,125     0,083     0,750     0,208     2,125     0,666     0,042     7,125     
    1KKA1Z300612     12     08.Feb.13 14:00     F     20.Feb.13 16:00     REPAIR CAR     20,000     16,042     2,125     0,833     4,125     0,083     0,750     0,208     2,125     0,666          And now the explanation to the query result:
    The AGE_1 is the difference in days between the 'CREATE_DATE' and IF EXSIST the STEP 'U' then STEP_DATE or if the STEP 'U' is not found in TABLE_2 then it should show the difference in days between the 'CREATE_DATE' and the 'SYSDATE'
    The AGE_2 is the difference in days between the STEP 'A' STEP_DATE and IF EXSIST the STEP 'R' then STEP_DATE or if the STEP 'R' is not found in TABLE_2 then it should show the difference in days between the 'CREATE_DATE' and the 'SYSDATE'
    The WAITING is the difference in days between CREATE_DATE and STEP 'A' STEP_DATE
    The following columns show the days how long the ORDER_NR stays in these STEP, if an ORDER_NR comes into the same STEP more then one time it should be calculated together.
    If the ORDER_NR skips a step it should show a zero in the specific field.
    I hope my explanation is good enough, my english skills are far away from good.
    Thanks all for your help.
    Greets Reinhard W.

    Hi,
    i changed this query:
    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
    select  t1.*,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_2,
            sum(
                case t2.wo_step
                  when 'B' then t2.next_step_date - t2.step_date
                end
               ) step_b
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nr,
               t1.priority,
               t1.create_date,
               t1.act_step,
               t1.step_date,
               t1.employee,
               t1.descriptionTo this:
    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
    select  t1.order_nr,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_2,
            sum(
                case t2.wo_step
                  when 'B' then t2.next_step_date - t2.step_date
                end
               ) step_b
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nrthen i get the ORA-00979 Error.
    Whats wrong?
    I have another question.
    How can i handle i i want to group to or more 'STEP's in one Column.
    in Case of this i want that the column 'STEP_B' contains all days for STEP 'B' and STEP '5'.
    I tried already with a + Operation like this:
    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
    select  t1.*,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_2,
            Round( sum(
                case t2.wo_step
                  when 'B' then t2.next_step_date - t2.step_date
                end
               ) +
            sum(
                case t2.wo_step
                  when '5' then t2.next_step_date - t2.step_date
                end
               ), 3 ) step_b
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nr,
               t1.priority,
               t1.create_date,
               t1.act_step,
               t1.step_date,
               t1.employee,
               t1.descriptionBut this does reply evertime a NULL.
    Thank You.

  • Need help with complex query

    Hi All
    I have the following requirement, please see the following table
    BIN_DATA_ID     TRAFFIC_SAMPLE_ID     END_INTV_TIME     BIN_1_DATA     BIN_2_DATA     BIN_3_DATA
    1     539     1100     0     34     19
    2     539     1200     0     65     18
    3     539     1300     0     51     17
    4     539     1400     0     65     27
    5     539     1500     0     99     48
    6     539     1600     0     426     138
    7     539     1700     0     151     62
    8     539     1800     0     80     32
    9     539     1900     0     31     11
    10     539     2000     0     37     11
    11     539     2100     0     24     9
    12     539     2200     0     16     5
    13     539     2300     0     27     12
    14     539     2400     0     55     20
    15     539     100     0     18     9
    16     539     200     0     134     52
    17     539     300     0     230     69
    18     539     400     0     15     7
    19     539     500     0     6     5
    20     539     600     0     47     23
    21     539     700     0     100     41
    22     539     800     0     196     43
    23     539     900     0     81     20
    24     539     1000     0     58     28
    25     539     1100     0     58     24
    26     539     1200     0     60     22
    27     539     1300     0     42     18
    28     539     1400     0     53     15
    29     539     1500     0     107     43
    30     539     1600     0     441     146
    31     539     1700     0     128     34
    32     539     1800     0     67     27
    33     539     1900     0     45     22
    34     539     2000     0     24     13
    35     539     2100     0     16     11
    36     539     2200     0     28     5
    37     539     2300     0     23     8
    38     539     2400     0     73     11
    39     539     100     0     16     3
    40     539     200     0     243     82
    41     539     300     0     121     55
    42     539     400     0     17     4
    43     539     500     0     5     5
    44     539     600     0     41     15
    45     539     700     0     101     34
    46     539     800     0     184     43
    47     539     900     0     69     15
    48     539     1000     0     51     18
    49     539     1100     0     61     25The above data showed is for only one"TRAFFIC_SAMPLE_ID"=539, what i want is i should ignore the first record and starting from the second record (in this example "END_INV_TIME" 1200) I need to find its pair which in this case is another 1200 and then find the average of AVG{(BIN_1_DATA+BIN_2_DATA+BIN_3_DATA) of day 1 +(BIN_1_DATA+BIN_2_DATA+BIN_3_DATA)  of day 2}, same is the case with rest all of teh records 1300,1400,1500.......
    Thanks

    Is this what you are looking for?
    Use a self-join with the "<" condition on the ID columns to make sure you don't join a row to itself or get two rows for each join.
    WITH
      csvs as
        ( select  '1,539,1100,0,34,19'    x  from dual union all   
          select  '2,539,1200,0,65,18'    x  from dual union all   
          select  '3,539,1300,0,51,17'    x  from dual union all   
          select  '4,539,1400,0,65,27'    x  from dual union all   
          select  '5,539,1500,0,99,48'    x  from dual union all   
          select  '6,539,1600,0,426,138'  x  from dual union all   
          select  '7,539,1700,0,151,62'   x  from dual union all   
          select  '8,539,1800,0,80,32'    x  from dual union all   
          select  '9,539,1900,0,31,11'    x  from dual union all   
          select  '10,539,2000,0,37,11'   x  from dual union all   
          select  '11,539,2100,0,24,9'    x  from dual union all   
          select  '12,539,2200,0,16,5'    x  from dual union all   
          select  '13,539,2300,0,27,12'   x  from dual union all   
          select  '14,539,2400,0,55,20'   x  from dual union all   
          select  '15,539,100,0,18,9'     x  from dual union all   
          select  '16,539,200,0,134,52'   x  from dual union all   
          select  '17,539,300,0,230,69'   x  from dual union all   
          select  '18,539,400,0,15,7'     x  from dual union all   
          select  '19,539,500,0,6,5'      x  from dual union all   
          select  '20,539,600,0,47,23'    x  from dual union all   
          select  '21,539,700,0,100,41'   x  from dual union all   
          select  '22,539,800,0,196,43'   x  from dual union all   
          select  '23,539,900,0,81,20'    x  from dual union all   
          select  '24,539,1000,0,58,28'   x  from dual union all   
          select  '25,539,1100,0,58,24'   x  from dual union all   
          select  '26,539,1200,0,60,22'   x  from dual union all   
          select  '27,539,1300,0,42,18'   x  from dual union all   
          select  '28,539,1400,0,53,15'   x  from dual union all   
          select  '29,539,1500,0,107,43'  x  from dual union all   
          select  '30,539,1600,0,441,146' x  from dual union all   
          select  '31,539,1700,0,128,34'  x  from dual union all   
          select  '32,539,1800,0,67,27'   x  from dual union all   
          select  '33,539,1900,0,45,22'   x  from dual union all   
          select  '34,539,2000,0,24,13'   x  from dual union all   
          select  '35,539,2100,0,16,11'   x  from dual union all   
          select  '36,539,2200,0,28,5'    x  from dual union all   
          select  '37,539,2300,0,23,8'    x  from dual union all   
          select  '38,539,2400,0,73,11'   x  from dual union all   
          select  '39,539,100,0,16,3'     x  from dual union all   
          select  '40,539,200,0,243,82'   x  from dual union all   
          select  '41,539,300,0,121,55'   x  from dual union all   
          select  '42,539,400,0,17,4'     x  from dual union all   
          select  '43,539,500,0,5,5'      x  from dual union all   
          select  '44,539,600,0,41,15'    x  from dual union all   
          select  '45,539,700,0,101,34'   x  from dual union all   
          select  '46,539,800,0,184,43'   x  from dual union all   
          select  '47,539,900,0,69,15'    x  from dual union all   
          select  '48,539,1000,0,51,18'   x  from dual union all   
          select  '49,539,1100,0,61,25'   x  from dual
    , wdata as 
        ( select  to_number(regexp_replace( x , '^(.*),(.*),(.*),(.*),(.*),(.*)$' , '\1' ))  as bin_data_id
               ,  to_number(regexp_replace( x , '^(.*),(.*),(.*),(.*),(.*),(.*)$' , '\2' ))  as traffic_sample_id
               ,  to_number(regexp_replace( x , '^(.*),(.*),(.*),(.*),(.*),(.*)$' , '\3' ))  as end_intv_time
               ,  to_number(regexp_replace( x , '^(.*),(.*),(.*),(.*),(.*),(.*)$' , '\4' ))  as bin_1_data
               ,  to_number(regexp_replace( x , '^(.*),(.*),(.*),(.*),(.*),(.*)$' , '\5' ))  as bin_2_data
               ,  to_number(regexp_replace( x , '^(.*),(.*),(.*),(.*),(.*),(.*)$' , '\6' ))  as bin_3_data
            from  csvs
    SELECT  a.traffic_sample_id
         ,  a.end_intv_time
         ,  ((a.bin_1_data + a.bin_2_data + a.bin_3_data) + (b.bin_1_data + b.bin_2_data + b.bin_3_data)) / 2  as av
      from  wdata   a
      join  wdata   b  on  ( a.traffic_sample_id = b.traffic_sample_id  and
                             a.end_intv_time     = b.end_intv_time      and
                             a.bin_data_id       < b.bin_data_id          )
    order  by 1, 2 ;

  • Need help with complex query with comma seperated

    Oracle version - 11.1.0.7.0
    Consider there are two tables table1 and table2
    Key---- ID
    A ---- 1
    A ---- 2
    A---- 3
    B ---- 4
    B ---- 5
    C ---- 6
    C ---- 8
    C ---- 9
    C ---- 10
    D ---- 11
    D ---- 12
    Table2
    ID
    1
    2
    6
    8
    11
    12
    I need result as in usedID column I should get comma seperated list of ID which are in table1 and table2 and in NOTUSEDID comma seperated list of ID which are in table1 but not in table2
    Key---- USEDID---- NOTUSEDID
    A ---- 1,2 ---- 3
    B ---- null ---- 4,5
    C ---- 6,8 ---- 9,10
    D ---- 11,12 ---- null

    Hi!
    Solution for Oracle 11g:
    SELECT A.KEY,
           listagg(decode(b.id, null, null, a.id), ',') WITHIN GROUP (ORDER BY  A.ID) AS USEDID,
           listagg(decode(b.id, null, a.id), ',') WITHIN GROUP (ORDER BY  A.ID) AS NOTUSEDID
      FROM TABLE1 A
           LEFT OUTER JOIN table2 b
           ON (A.ID = b.ID)
    GROUP BY a.key;
    Solution for databases prior to Oracle 11g:
    Please note that the function wm_concat is undocumented and can't be sorted!
    SELECT A.KEY,
           wm_concat(decode(b.id, null, null, a.id)) AS USEDID,
           wm_concat(decode(b.id, null, a.id)) AS NOTUSEDID
      FROM TABLE1 A
           LEFT OUTER JOIN table2 b
           ON (A.ID = b.ID)
    GROUP BY A.KEY;I used the following test case:
    create table table1(key varchar2(255), id number);
    CREATE TABLE table2(ID NUMBER);
    insert into table1 values('A', 1);
    INSERT INTO table1 VALUES('A', 2);
    INSERT INTO table1 values('A', 3);
    INSERT INTO table1 VALUES('B', 4);
    INSERT INTO table1 VALUES('B', 5);
    INSERT INTO table1 VALUES('C', 6);
    INSERT INTO table1 values('C', 8);
    INSERT INTO table1 VALUES('C', 9);
    INSERT INTO table1 VALUES('C', 10);
    INSERT INTO table1 values('D', 11);
    insert into table1 values('D', 12);
    insert into table2 values(1);
    insert into table2 values(2);
    insert into table2 values(6);
    insert into table2 values(8);
    insert into table2 values(11);
    insert into table2 values(12);
    commit;Best regards,
    Matt
    Edited by: Matt Schulz on Oct 12, 2011 12:43 PM

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, 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_Number, Invoice_Type, Vendor_Number. When there are no multiple 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-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Please, need help with a query

    Hi !
    Please need help with this query:
    Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
    Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
    select distinct a.id,
    create_date,
    a.loanid,
    a.rate,
    a.pays,
    a.gracetime,
    a.emailtosend,
    d.first_name,
    d.last_name,
    a.user_id
    from CLAL_LOANCALC_DET a,
    loan_Calculator b,
    bv_user_profile c,
    bv_mr_user_profile d
    where b.loanid = a.loanid
    and c.NET_USER_NO = a.resp_id
    and d.user_id = c.user_id
    and a.is_partner is null
    and a.create_date between
    TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
    TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    order by a.create_date

    Take a look on the syntax :
    max(...) keep (dense_rank last order by ...)
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#i1000901
    Nicolas.

  • Please need help with this query

    Hi !
    Please need help with this query:
    Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
    Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
    select distinct a.id,
    create_date,
    a.loanid,
    a.rate,
    a.pays,
    a.gracetime,
    a.emailtosend,
    d.first_name,
    d.last_name,
    a.user_id
    from CLAL_LOANCALC_DET a,
    loan_Calculator b,
    bv_user_profile c,
    bv_mr_user_profile d
    where b.loanid = a.loanid
    and c.NET_USER_NO = a.resp_id
    and d.user_id = c.user_id
    and a.is_partner is null
    and a.create_date between
    TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
    TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    order by a.create_date

    Perhaps something like this...
    select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
    from (
          select distinct a.id,
                          create_date,
                          a.loanid,
                          a.rate,
                          a.pays,
                          a.gracetime,
                          a.emailtosend,
                          d.first_name,
                          d.last_name,
                          a.user_id,
                          max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
          from CLAL_LOANCALC_DET a,
               loan_Calculator b,
               bv_user_profile c,
               bv_mr_user_profile d
          where b.loanid = a.loanid
          and   c.NET_USER_NO = a.resp_id
          and   d.user_id = c.user_id
          and   a.is_partner is null
          and   a.create_date between
                TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
                TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    where create_date = max_create_date
    order by create_date

  • Need help with Blog, Wiki and Gallery

    Hi Team,
    Need help with Blog, Wiki and Gallery startup. I have newly started visiting forums and quite interested to contribute towards these areas also.
    Please help.
    Thanks,
    Santosh Singh
    Santosh Singh

    Hello Santhosh,
    Blog is for Microsoft employees only. However, you can contribute towards WIKI and GALLERY using the below links.
    http://social.technet.microsoft.com/wiki/
    http://gallery.technet.microsoft.com/

  • Need help with conditional query

    guys this is just an extension of this post that Frank was helping me with. im reposting because my requirements have changes slightly and im having a hell of a time trying to modify the query.
    here is the previous post.
    need help with query that can look data back please help.
    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)
      )data
    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','00','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','7240','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','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 ('360055','360055','7200','4730','02','10','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 ('360055','360055','7600','4730','02','10','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','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','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','7240','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','7240','4730','02','11','2','600');
    I need to find the greatest grant year for the grant by a period parameter.
    once i find the greatest year i need to check the value of period 14 for that grant for the previous year and add it to the budget amount for that grant. however if their is an entry in the greatest year for period 00 then i need to ignore the period 14 of previous year and do this calculation current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    here is the query supplied by frank kulash who gracefully put this together for me.
    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
    ;Miguel

    Hi, Miguel,
    Are you waying that, when the greatest year that has :given_period also has period='00' (or '0', or whatever you want to use), then you want to double the budget from the given_period (as well as subtract the budget from the '00', and not count the pevious year's '14')? If so, add another condition to the CASE statement which decides what you're SUMming:
    WITH     got_greatest_year     AS
         SELECT       TO_NUMBER (fgl_grnt_year)     AS grnt_year
         ,       fgl_period
         ,       TO_NUMBER (fgl_budget)     AS budget
         ,       MAX ( CASE
                       WHEN  fgl_period = :given_period
                       THEN  TO_NUMBER (fgl_grnt_year)
                      END
                    ) OVER ()     AS greatest_year
         FROM       fgl
    ,     got_cnt_00     AS
         SELECT     grnt_year
         ,     fgl_period
         ,     budget
         ,     greatest_year
         ,     COUNT ( CASE
                       WHEN  grnt_year     = greatest_year
                       AND       fgl_period     = '00'
                       THEN  1
                         END
                    ) OVER ()          AS cnt_00
         FROM    got_greatest_year
    SELECT       SUM ( CASE
                        WHEN  grnt_year     = greatest_year                    -- New
                  AND       fgl_period     = :given_period                    -- New
                  AND       cnt_00     > 0            THEN  budget * 2     -- New
                        WHEN  grnt_year     = greatest_year
                  AND       fgl_period     = :given_period       THEN  budget
                        WHEN  grnt_year     = greatest_year
                  AND       fgl_period     = '00'            THEN -budget
                        WHEN  grnt_year     = greatest_year - 1
                  AND       fgl_period     = '14'     
                  AND       cnt_00     = 0            THEN  budget
                    END
               )          AS total_budget
    FROM       got_cnt_00
    ;You'll notice this is the same as the previous query I posted, except for 3 lines maked "New".

  • Need help with a query

    Hi,
    I need help with the following query. I want the balance (bal) with the latest exchange rate available.
    Sample table & data
    with
    FX_RATE as
    select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
    select 12, 1, 48 from dual union
    select 13, 2, 54 from dual union
    select 14, 2, 55 from dual union
    select 15, 3, 56 from dual union
    select 15, 2, 49 from dual),
    TBL_NM as
    select 13 as p_date, 2 as p_curr, 200 as bal from dual union
    select 14, 2, 200 from dual union
    select 15, 2, 200 from dual union
    select 16, 2, 200 from dual union
    select 17, 2, 200 from dual union
    select 11, 5, 100 from dual
    select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1 on (id_curr = p_curr and F1.id_date = T.p_Date)In the above query for p_date 16 & 17 and p_curr 2 it returns just balance multiplied by exchange rate 1"default". But i want the balance to have data as per latest exchange rate which is of exchange rate 15.
    I tried this but returns error ORA-01799: a column may not be outer joined to a subquery ..
    with
    FX_RATE as
    select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
    select 12, 1, 48 from dual union
    select 13, 2, 54 from dual union
    select 14, 2, 55 from dual union
    select 15, 3, 56 from dual union
    select 15, 2, 49 from dual),
    TBL_NM as
    select 13 as p_date, 2 as p_curr, 200 as bal from dual union
    select 14, 2, 200 from dual union
    select 15, 2, 200 from dual union
    select 16, 2, 200 from dual union
    select 17, 2, 200 from dual union
    select 11, 5, 100 from dual
    select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1
    on (id_curr = p_curr and F1.id_date = (select max(F2.id_date) from FX_RATE F2 where F2.id_curr = T.p_curr and F2.id_Date <=  T.p_date))Please advice on how i can achieve this ..

    The entire query wud be like this .. I've to incorporate in here
    CREATE MATERIALIZED VIEW MV_DUMMY
    BUILD IMMEDIATE
    REFRESH FORCE ON DEMAND
    AS
        SELECT T.ID_TSACTION_RELEASED                                                                                
        BAL.ID_CONTRACT_BALANCE                                                                                                                                                                                                                                                                           AS ID_CONTRACT_BALANCE,   
        T.N_REFERENCE_NUMBER                                                                                          
        T.INSTRUMENT_N_REFERENCE                                                                                      
        T.ITEM_NUMBER                                                                                                   
        T.EXTERNAL_SYSTEM_ID                                                                                            
        T.SEQUENCE_NUMBER                                                                                               
        T.ID_RELEASED_DATE                                                                                              
       ROUND(BAL.LC_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)                           
        BAL.LIABILITY_BALANCE                                                                                              
        BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                                                                   
        BAL.LIABILITY_CHANGE_USD                                                                                           
        BAL.MEMO_LIABILITY_BALANCE                                                                                         
        BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                                                              
        BAL.MEMO_LIABILITY_CHANGE_USD                                                                                      
        BAL.ORIGINAL_FACE_AMOUNT                                                                                           
        decode(T.TENOR_CODE,'Time','T','Sight','S','Split Sight Time','SST','Split Multiple Time','SMT',T.TENOR_CODE)
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN T.ID_LIABILITY_CIF
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN T.Id_Beneficiary
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN T.ID_Applicant
        END PRIMARY_CUSTOMER_ID,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN plbcif.EXTERNAL_SYSTEM_ID
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN PBCIF.EXTERNAL_SYSTEM_ID
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN pappcif.EXTERNAL_SYSTEM_ID
        END PRIMARY_CUSTOMER_EXT_SYS_ID,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN plbcif.CIF_NAME
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN PBCIF.CIF_NAME
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN pappcif.CIF_NAME
        END PRIMARY_CUSTOMER_NAME,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN plbbac.BAC
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN pbbac.BAC
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN pappbac.BAC
        END PRIMARY_CUST_BAC_CODE,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN nvl(plbmg.MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN nvl(pbmg.MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN nvl(pappmg.MARKET,'NOT APPLICABLE')
        END PRIMARY_CUST_MARKET,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN nvl(plbmg.SUB_MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN nvl(pbmg.SUB_MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN nvl(pappmg.SUB_MARKET,'NOT APPLICABLE')
        END PRIMARY_CUST_SUB_MARKET
      FROM F_TSACTION_RELEASED T
      LEFT OUTER JOIN D_BAC_CODE BAC
      ON (T.BAC_CODE_LIABILITY = BAC.BAC_CODE)
      LEFT OUTER JOIN REF_BAC_SORT_CODE REF_BAC
      ON (T.BAC_CODE_LIABILITY = REF_BAC.BAC)
      LEFT OUTER JOIN F_CONTRACT_BALANCE BAL
      ON (T.ID_TSACTION_RELEASED = BAL.ID_TSACTION_RELEASED)
      LEFT OUTER JOIN D_MARKET_SEGMENT MG
      ON (T.ID_MARKET_SEGMENT = MG.ID_MARKET_SEGMENT)
      LEFT OUTER JOIN D_DATE DT
      ON (DT.ID_DATE = T.ID_RELEASED_DATE)
      LEFT OUTER JOIN D_DATE DB
      ON (DB.ID_DATE = BAL.ID_RELEASED_DATE)
      LEFT OUTER JOIN D_PROCESSING_UNIT PU
      ON (PU.ID_PROCESSING_UNIT = T.ID_PROCESSING_UNIT)
      LEFT OUTER JOIN D_BIR_PRODUCT BIRPROD
      ON (BIRPROD.ID_BIR_PRODUCT=T.ID_BIR_PRODUCT)
      LEFT OUTER JOIN D_GTS_PRODUCT_TYPE GTSPROD
      ON (GTSPROD.ID_GTS_PRODUCT_TYPE= T.ID_GTS_PRODUCT_TYPE)
      LEFT OUTER JOIN D_GTS_TSACTION_TYPE GTST
      ON (GTST.ID_GTS_TSACTION_TYPE = T.ID_GTS_TSACTION_TYPE)
      LEFT OUTER JOIN D_CURRENCY CCYT
      ON (CCYT.ID_CURRENCY = T.ID_TSACTION_CURRENCY)
      LEFT OUTER JOIN d_cif lcif
      ON (lcif.id_cif = T.id_liability_cif)
      LEFT OUTER JOIN d_cif lbcif
      ON (lbcif.id_cif = bal.id_liability_cif)
      LEFT OUTER JOIN d_cif bcif
      ON (bcif.id_cif = T.id_BENEFICIARY)
      LEFT OUTER JOIN d_cif icif
      ON (icif.id_cif = T.id_ISSUING_BANK)
      LEFT OUTER JOIN d_cif acif
      ON (acif.id_cif = T.id_ADVISING_BANK)
      LEFT OUTER JOIN d_cif appcif
      ON (appcif.id_cif = T.id_applicant)
      LEFT OUTER JOIN d_state astate
      ON (astate.id_state = acif.id_state)
      LEFT OUTER JOIN d_state bstate
      ON (bstate.id_state = bcif.id_state)
      LEFT OUTER JOIN d_state lstate
      ON (lstate.id_state = lcif.id_state)
      LEFT OUTER JOIN d_state lbstate
      ON (lbstate.id_state = lbcif.id_state)
      LEFT OUTER JOIN d_state istate
      ON (istate.id_state = icif.id_state)
      LEFT OUTER JOIN d_state appstate
      ON (appstate.id_state = appcif.id_state)
      LEFT OUTER JOIN D_TSACTION_SOURCE TSrc
      ON (T.ID_TSACTION_SOURCE = TSrc.ID_TSACTION_SOURCE)
      LEFT OUTER JOIN D_COUNTRY LCTRY
      ON (LCTRY.ID_COUNTRY = lcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY LBCTRY
      ON (LBCTRY.ID_COUNTRY = lbcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY BCTRY
      ON (BCTRY.ID_COUNTRY = bcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY ICTRY
      ON (ICTRY.ID_COUNTRY = icif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY ACTRY
      ON (ACTRY.ID_COUNTRY = acif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY APPCTRY
      ON (APPCTRY.ID_COUNTRY = appcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY PCTRY
      ON (PCTRY.ID_COUNTRY = T.ID_PRESENTER_COUNTRY)
      LEFT OUTER JOIN D_LOCATION LOC
      ON (LOC.ID_LOCATION = T.ID_PROCESSING_LOCATION)
      LEFT OUTER JOIN D_CURRENCY BCCYT
      ON (BCCYT.ID_CURRENCY = BAL.ID_LIABILITY_CURRENCY)
      LEFT OUTER JOIN D_CURRENCY BALCYT
      ON (BALCYT.ID_CURRENCY = BAL.ID_BALANCE_CURRENCY)
      LEFT OUTER JOIN d_liability_type li
      ON (li.id_liability_type = BAL.id_liability_type)
      LEFT OUTER JOIN d_cif plbcif
      ON (plbcif.id_cif = T.id_liability_cif)
      LEFT OUTER JOIN REF_BAC_SORT_CODE plbbac
      ON (plbcif.bac_code=plbbac.bac)
      LEFT OUTER JOIN D_MARKET_SEGMENT plbmg
      ON (plbbac.SORT_CODE=plbmg.MARKET_SEGMENT)
      LEFT OUTER JOIN d_cif pbcif
      ON (pbcif.id_cif = T.id_BENEFICIARY)
      LEFT OUTER JOIN REF_BAC_SORT_CODE pbbac
      ON (pbcif.bac_code=pbbac.bac)
      LEFT OUTER JOIN D_MARKET_SEGMENT pbmg
      ON (pbbac.SORT_CODE=pbmg.MARKET_SEGMENT)
      LEFT OUTER JOIN d_cif pappcif
      ON (pappcif.id_cif = T.id_applicant)
      LEFT OUTER JOIN REF_BAC_SORT_CODE pappbac
      ON (pappcif.bac_code=pappbac.bac)
      LEFT OUTER JOIN D_MARKET_SEGMENT pappmg
      ON (pappbac.SORT_CODE=pappmg.MARKET_SEGMENT)
      LEFT OUTER JOIN D_CURRENCY LOCALCYT
      ON (LOCALCYT.alpha_code = PU.local_ccy)
      LEFT OUTER JOIN D_BRANCH Branch              
      ON (T.ID_BRANCH  = Branch.ID_BRANCH )
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
      ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
      ON (LOCALCYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCALCYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
      ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Note the lines
    ROUND(BAL.MN_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)                           
    BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                                                                   
    BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                 
    And
    LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
      ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
      ON (LOCAMNYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCAMNYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
      ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Thsi is where I need to incorporate the change

  • Need help with saving data and keeping table history for one BP

    Hi all
    I need help with this one ,
    Scenario:
    When adding a new vendor on the system the vendor is suppose to have a tax clearance certificate and it has an expiry date, so after the certificate has expired a new one is submitted by the vendor.
    So i need to know how to have SBO fullfil this requirement ?
    Hope it's clear .
    Thanks
    Bongani

    Hi
    I don't have a problem with the query that I know I've got to write , the problem is saving the tax clearance certificate and along side it , its the expiry date.
    I'm using South African localization.
    Thanks

  • Need Help with INSTR Query

    Hi,
    I have column which is having values like
    EMEA/MEA/IT
    EMEA/WE/GE
    EMEA/MEA/SA
    EMEA/WE/jk
    but i need to get all these rows based on some front selected values where we will select like EMEA/MEA & EMEA/WE.But that value will be ';' separated like EMEA/MEA%;EMEA/WE%.Based on this value l need to retrieve all the rows based on this value (Note ';' as the delimiter) .I tried with INSTR , but not able to sort out.
    Could some one please me on this one how to make this condition in my query.
    Thanks,

    Thanks Frank for your response.
    Table will have thousands of rows where column which I comparing(OU_DIV_REG) will be like with many combination's.I am attaching some data for reference.
    EMEA/DIV/
    EMEA/DIV/HYP
    EMEA/EE
    EMEA/EE&CIS
    EMEA/EE&CIS/
    EMEA/EE&CIS/CENT
    EMEA/EE&CIS/CIS
    EMEA/EE&CIS/GR
    EMEA/EE&CIS/RO
    EMEA/EE&CIS/RTG
    EMEA/EE&CIS/SBL
    EMEA/EE&CIS/SEES
    EMEA/EE&CIS/TR
    EMEA/EMEA_OTM/
    EMEA/FMEA/FR
    EMEA/FMEA/MEA
    EMEA/IL
    EMEA/MEA
    EMEA/MEA/
    EMEA/MEA/EG
    EMEA/MEA/SA
    EMEA/MEA/ZA
    EMEA/NE/BLX
    EMEA/SE
    EMEA/SE/ALPS
    EMEA/SE/IBE
    EMEA/UK
    EMEA/UK/
    But I am using this condition in APEX.Actually I have a report with return query and that will execute. I need this condition to be in where clause.I am attaching my APEX report query for your reference. I updating that where clause condition in BOLD letters where i need to add this condition that will consider all the rows from the table wherever input from APEX page will be like fallowing with ';' as delimter.
    EMEA/MEA%;EMEA/EE&CIS%
    Considering this input values, I need to consider all the rows above where that column value us having EMEA/MEA% and EMEA/EE&CIS%.
    I tried adding the where clause which in BOLD letter (cluster condition).Please let me know will it work or also I need to how to add these XMLtable separation based on ',' in where clause.
    For you reference I am just my full report query(which is not needed i know - but just have the full understanding).
    DECLARE
    lc_query VARCHAR2(4000);
    BEGIN
    lc_query := 'SELECT INITCAP(SUBSTR(end_cli_name,1,20)) Customer
    ,DECODE(cps_id,NULL,INITCAP(SUBSTR(title,1,20)),''<a href="http://cpotsi.oraclecorp.com/pls/cpotsiweb/CPOTSI.EP_WITHDRDTA_RAG_L.show_cps?p_cps_id=''||cps_id||''&p_uptodate=''||:P_DD||''" target=_blank>''||INITCAP(SUBSTR(title,1,20))||''</a>'') Project
    ,ou_ctry_code
    ,funding_amnt
    ,budgeted_margin_amnt
    ,TO_NUMBER(eac_margin_amnt)
    ,decode(substr(PREV_CPS_RAGU_L_1,1,1),
    ''R'',''<img src="#APP_IMAGES#red.jpg" alt="Red">'',
    ''A'',''<img src="#APP_IMAGES#amber.jpg" alt="Amber">'',
    ''G'',''<img src="#APP_IMAGES#green.jpg" alt="Green">'',
    ''U'',''<img src="#APP_IMAGES#unknown.jpg" alt="Unknown">'',
    ''<img src="#APP_IMAGES#unknown.jpg" alt="Unknown">'') RAGU
    FROM emea_pmr_disco_input WHERE
    month=:P_SELECTED_MONTH
    AND year=:P_SELECTED_YEAR
    AND region IN (SELECT region_code
    FROM emea_pmr_regions
    START WITH ( INSTR('':''||:P_SELECTED_REGION||'':'','':''||region_code||'':'',1,1) > 0 )
    CONNECT BY PRIOR region_code=parent_region_code)
    AND prof_com_text LIKE :P_SELECTED_INDUSTRY ';
    IF :P_SELECTED_CLUSTER <> '%' THEN
    lc_query := lc_query ||
    *' AND upper(ou_div_reg) LIKE ''*
    SUBSTR(:P_SELECTED_CLUSTER,1,INSTR(:P_SELECTED_CLUSTER,'';'',1,1)-1 )'' OR
    upper(ou_div_reg) LIKE ''
    SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,1)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,2) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,1)-1) ) ) ''
    OR upper(ou_div_reg) LIKE ''
    SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,2)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,3) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,2)-1) ) ) ''
    OR upper(ou_div_reg) LIKE ''
    SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,3)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,4) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,3)-1) ) ) ''
    OR upper(ou_div_reg) LIKE ''
    SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,4)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,5) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,4)-1) ) ) ''
    OR upper(ou_div_reg) LIKE ''
    SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,5)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,6) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,5)-1) ) ) ''
    OR upper(ou_div_reg) LIKE ''
    SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,6)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,7) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,6)-1) ) ) ''
    END IF;
    IF :P1_TIER2 <> '%' THEN
         lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier2)||'';'','';''||upper(T2)||'';'',1,1) > 0 ';
         END IF;
         IF :P1_TIER3 <> '%' THEN
              lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier3)||'';'','';''||upper(T3)||'';'',1,1) > 0 ';
         END IF;
         IF :P1_TIER4 <> '%' THEN
              lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier4)||'';'','';''||upper(T4)||'';'',1,1) > 0 ';
         END IF;
         IF :P_SELECTED_COUNTRY <> '%' THEN
         lc_query := lc_query || ' AND INSTR('';''||upper(:P_SELECTED_COUNTRY)||'';'','';''||upper(ou_ctry_code)||'';'',1,1) > 0 ';
         ELSE
         IF :P_IS_ADMIN = 'N' THEN
         lc_query := lc_query || 'AND ou_ctry_code IN (SELECT country_code
         FROM emea_pmr_user_countries
         WHERE INSTR('':''||:P_SELECTED_REGION||'':'','':''||region_code||'':'',1,1) > 0
         AND user_id = :P_SELECTED_USER_ID
         AND view_access = ''Y'') ';
         END IF;
    END IF;
    IF :P_TOPMARLOV='Current' THEN
    lc_query := lc_query || ' AND UPPER(ep_state_name)=''STARTED''';
    ELSIF :P_TOPMARLOV='Closed' THEN
    lc_query := lc_query || ' AND UPPER(ep_state_name)=''CLOSED''';
    END IF;
    IF:P1_MARGIN_STATUS='R' THEN
    lc_query := lc_query || ' AND
    UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''R''';
    ELSIF:P1_MARGIN_STATUS='G' THEN
    lc_query := lc_query || ' AND
    UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''G''';
    ELSIF:P1_MARGIN_STATUS='A' THEN
    lc_query := lc_query || ' AND
    UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''A''';
    ELSIF:P1_MARGIN_STATUS='U' THEN
    lc_query := lc_query || ' AND
    UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''U''';
    END IF;
    htp.p(lc_query);
    RETURN lc_query;
    END;

  • Hi.. need help with a query

    hello guys :)
    I need help with this exercise:
    Find the most common cooking method in recipes that contain tomatoes.
    the 4 tables:
    t_recipes
    --recipe_no
    --recipe_name
    t_products
    --product_no
    -product_name [tomatoes,cucumbers, onions]
    t_integration
    --product_no
    --recipe_no
    t_cooking_mode
    recipe_no
    mode [Frying,baking]
    I am realy lost :S
    thank you

    Hi,
    851072 wrote:
    Thank you for your comment :)
    But... I didn`t understand the first partSorry, what part is that? You probably understood "Welcome to the forum!" It looks like you understood most of what I said, perhaps before I said it. You seem to be on the right track.
    Unlike talking to a co-worker in the next cube, exchanging messages with someone on this forum takes a fair amount of time, so it's worth the time it takes to explain things very clearly, more than you would in conversation. Post all the relevant information, and say exactly what the problem is.
    amm i tried to do this:
    select t_recipes.recipe_name, count(t_cooking_mode.cooking_mode)
    from (t_cooking_mode INNER JOIN t_integration ON t_cooking_mode.recipe_no = t_integration.recipe_no )
    INNER JOIN t_products ON t_integration.product_no = t_products.product_no)
    WHERE t_products.product_name = 'tomatoes'
    GROUP BY t_recipes.recipe_name
    help?Please help by posting whatever you know about the problem. For example, if there's a error message, post the complete error message, including the line number.
    Help the people who want to help you by formatting your code and making it easy to read and understand. This will help you, too.
    For example, here's exactly what you posted, with only the white-space changed to make parallel items, such as parentheses, line up nicely:
    select        t_recipes.recipe_name
    ,       count(t_cooking_mode.cooking_mode)
    from             (          t_cooking_mode
                INNER JOIN      t_integration      ON t_cooking_mode.recipe_no = t_integration.recipe_no
    INNER JOIN      t_products      ON t_integration.product_no = t_products.product_no
    WHERE       t_products.product_name      = 'tomatoes'
    GROUP BY  t_recipes.recipe_nameWhen you format your code like this, it can be very easy to spot errors like unbalanced parentheses. In this case, the ')' right before the WHERE clause has no matching '('. You don't need to use any parentheses at all in the FROM clause. You can simply say:
    FROM     t_cooking_mode
    JOIN      t_integration      ON t_cooking_mode.recipe_no = t_integration.recipe_no
    JOIN      t_products      ON t_integration.product_no = t_products.product_no
    WHERE     ...INNER JOIN is the default kind of join, which makes sense, since the majority of all joins are inner joins. I usually say JOIN (instead of INNER JOIN) because it makes the code more compact and easier to read (at least for me), but I won't be maintaining your code, so do what's best for you.
    What are you trying to find in this problem? Is it a recipe name or a cooking mode? If it's a cooking mode, the why do you have t_recipes.reciple_name in the SELECT (and GROUP BY) clause? Shouldn't you be using some other column, from some other table?
    If I understand the problem correctly, the t_recipes table is not needed in this problem. You won't necessarily use every table in every query.
    When you post formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help with complex column creation command

    Hello, all
    I need help with a complex column creation command and SQL anywhere help is not sufficient for it.
    Here is the situation:
    I need to write a generic DDL "alter table" command, which can add/modify columns without knowing in advance if they already exist in the destination table.
    Is there a command, which looks like:
    alter table "table1" add (on existing modify) column1 <datatype> <default> ?
    Thank you,
    Arcady

    Hi.
    I don't think this is supported in alter table command. But you can code that inside an if statement which queries systables & syscolumns. Your code should be something like that:
    if (select count(*) from sysobjects, syscolumns where sysobjects.id = syscolumns.id and sysobjects.name = 'some_table' and syscolumns.name = 'some_column') < 1
    begin
        alter table some_table add some_column numeric(12) not null
    end
    This is an example..
    Andreas.

  • Need help with Airport Express and so on.

    Ok so my main problem before getting into what I need help with here is that our MacBooks and now my iPhone 6 plus isn't staying online. Keep getting booted off and then I either have to select the network again or it will eventually go back on. If anyone has a solution or so please feel free to answer that as well. I'm running on Roadrunner with a Netgear 600 wireless router and a motorola modem. Both of which I'll leave the link to below for a better look.
    My Main Question: So I'm looking at a new wireless router mainly and possibly a new modem. I know Apple products are trustworthy but how good is the Airport Express and other Airport products. Also what is the Maximum speed and Maximum data speed for the cheapest express station and if anyone knows the speeds of the other devices it would be greatly appreciated.

    DSL Router to Netgear 5-port Switch and I used the switch to connect to Airport Extreme, TV, Blue-Ray DVD player and DirecTV Receiver.
    The AirPort Extreme base station (AEBS) is a router so it will do what you need.
    You need to reconfigure your setup. Connect the WAN port of the AEBS to the DSL router. Then connect the Netgear switch to one of the LAN ports on the AEBS. The AEBS will properly share the connection.

Maybe you are looking for

  • Spry Vertical Menu Bar not working in IE8

    I've upgraded to 1.6.1, but it still doesn't work in IE8 unless in compatibility mode.  http://jimgreenrealty.com/Test.html Works fine in other browsers and other Spry elements appear to work normally in IE8.  Can anyone help? Thanks, Steve B.

  • Nokia 6500 Classic Help Needed!

    Helo i have a Nokia 6500 Classic and i want to do a hard reset, it's also called factory settings. I'm not sure if the code to reset the phone to the factory settings has been edited. But i have tried 12345 and the phone says the code is wrong. So an

  • What's this error message?

    I lost my iTunes due to my on fault. I'm trying to re-download but I get this message: The folder "iTunes" cannot be found or created, and is required. The default location for this folder is inside the "My Music" folder. There are no files in "My Mu

  • Best Practices for securing VTY lines?

    Hi all, The thread title makes this sound like a big post but it's not.  If my router has say., 193 VTY lines as a maximum, but by default running-config has only a portion of those mentioned, should I set any configs I do on all lines, or just on th

  • Iwork on a macbook air.

    So I've been looking into getting a Macbook air for my first mac as a change from using windows seven. I'm a student in year 11 and I need to use word editors and such. I know the Macbook air doesn't have a optical disc drive so I was thinking about