Help required in writing a query

hi
Consider a table (ShogenValue) with following data:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 40001 B0001 2
4329 1 50300 B0001 3
4329 1 40001 C0001 4
4329 1 50300 C0001 5
4329 1 60001 C0001 6
Select
     si_val
From
     ShogenValue
Where
model_id = 4329
And
     header_id = 1
And
serial_no = '60001'
Is it possible to write a modified version of above query which will bring the following result:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 50300 B0001 3
4329 1 60001 C0001 6
Meaning if a record exists for a particular shogen_no (Shogen_no C0001 has value corrosponding to '60001' in above query), pick it up, if it
does not exist (Shogen_no B0001 does not have value corrosponding to '60001' in above case) then pick a record with one level less serial number ('50300' in above case) and so on.
Thanx
Regards
Omer Imtiaz

This should help, although it will probably not perform. Try it and see what the plan for it is.
SELECT
FROM
  shogenvalue sv,
  (SELECT
    max(serial_no) serial_no_max,
    shogen_no
  FROM
    shogenvalue
  WHERE
    model_id = 4329
    AND header_id = 1
    AND serial_no <= '60001'
  GROUP BY
    shogen_no
  ) svm
WHERE
  sv.serial_no = svm.serial_no_max
  AND sv.shogen_no = svm.shogen_no
;HTH,
Lennert

Similar Messages

  • Help required in writing the query

    I have the following level accounts
    10000
    11000
    11100
    11101
    11200
    11201
    12000
    12100
    12101
    12102
    12103
    20000
    21000
    21100
    21101
    22000
    22101
    21200
    21201
    I have to take the amount of the child account and sum it to the parent account as below:
    11100 = 11101 + 11102 - 11103+.........
    11000 = 11100 + 11200 + 11300+.........
    10000 = 11000 + 12000 + 13000+.........
    21100 = 21101 + 21102 - 21103+.........
    21000 = 21100 + 21200 + 21300+.........
    20000 = 21000 + 22000 + 23000+.........
    Please help...
    Thanks in advance.

    SQL> with t as (
      2             select 10000 ACCOUNT, NULL BEG_BAL, NULL END_BAL from dual union all
      3             select 11000,NULL,NULL from dual union all
      4             select 11100,NULL,NULL from dual union all
      5             select 11101,1750.00,4150.00 from dual union all
      6             select 11102,1550.00,3150.00 from dual union all
      7             select 11103,1650.00,3200.00 from dual union all
      8             select 11200,NULL,NULL from dual union all
      9             select 11201,800.00,1250.00 from dual union all
    10             select 11202,1550.00,3150.00 from dual union all
    11             select 12000,NULL,NULL from dual union all
    12             select 12100,NULL,NULL from dual union all
    13             select 12101,1200.00,5000.00 from dual union all
    14             select 12102,1500.00,3000.00 from dual union all
    15             select 12103,1550.00,2750.00 from dual union all
    16             select 20000,NULL,NULL from dual union all
    17             select 21000,NULL,NULL from dual union all
    18             select 21100,NULL,NULL from dual union all
    19             select 21101,2000.00,6500.00 from dual union all
    20             select 21102,1500.00,3500.00 from dual union all
    21             select 21103,1750.00,3550.00 from dual union all
    22             select 22000,NULL,NULL from dual union all
    23             select 22100,NULL,NULL from dual union all
    24             select 22101,1550.00,3550.00 from dual union all
    25             select 22102,2550.00,5550.00 from dual union all
    26             select 21200,NULL,NULL from dual union all
    27             select 21201,2550.00,6500.00 from dual union all
    28             select 21202,3550.00,7500.00 from dual
    29            )
    30  select  account,
    31          beg_bal,
    32          end_bal,
    33          sum(beg_bal) over(order by account range between current row and grouping_window follow
    ing) group_beg_bal,
    34          sum(end_bal) over(order by account range between current row and grouping_window follow
    ing) group_end_bal
    35    from  (
    36           select  t.*,
    37                   case
    38                     when account / 10000 = trunc(account / 10000) then 9999
    39                     when account / 1000 = trunc(account / 1000) then 999
    40                     when account / 100 = trunc(account / 100) then 99
    41                     when account / 10 = trunc(account / 10) then 9
    42                     else 0
    43                   end grouping_window
    44             from  t
    45          )
    46  order by account
    47  /
       ACCOUNT    BEG_BAL    END_BAL GROUP_BEG_BAL GROUP_END_BAL
         10000                               11550         25650
         11000                                7300         14900
         11100                                4950         10500
         11101       1750       4150          1750          4150
         11102       1550       3150          1550          3150
         11103       1650       3200          1650          3200
         11200                                2350          4400
         11201        800       1250           800          1250
         11202       1550       3150          1550          3150
         12000                                4250         10750
         12100                                4250         10750
       ACCOUNT    BEG_BAL    END_BAL GROUP_BEG_BAL GROUP_END_BAL
         12101       1200       5000          1200          5000
         12102       1500       3000          1500          3000
         12103       1550       2750          1550          2750
         20000                               15450         36650
         21000                               11350         27550
         21100                                5250         13550
         21101       2000       6500          2000          6500
         21102       1500       3500          1500          3500
         21103       1750       3550          1750          3550
         21200                                6100         14000
         21201       2550       6500          2550          6500
       ACCOUNT    BEG_BAL    END_BAL GROUP_BEG_BAL GROUP_END_BAL
         21202       3550       7500          3550          7500
         22000                                4100          9100
         22100                                4100          9100
         22101       1550       3550          1550          3550
         22102       2550       5550          2550          5550
    27 rows selected.
    SQL> SY.

  • Help needed  in writing a Query/Procedure

    Hello All,
    Need all ur help in writing a query or procedure
    Lets say the Table name is DEMO
    There i have one column like num it has values
    1
    2
    3
    4
    5
    8
    9
    10
    my query output should be
    1-5
    8-10
    i,e .. if the diff between two rows is greater than 1 then it result should be in a separate group
    I need a query/Procedure for this. Kindly help
    Regards,
    Chandra

    Tried obtaining the output using SQL and the result is as follows:
    SQL> WITH T AS
      2  (
      3  SELECT 1 COL1 FROM DUAL
      4  UNION
      5  SELECT 2 COL1 FROM DUAL
      6  UNION
      7  SELECT 3 COL1 FROM DUAL
      8  UNION
      9  SELECT 4 COL1 FROM DUAL
    10  UNION
    11  SELECT 5 COL1 FROM DUAL
    12  UNION
    13  SELECT 8 COL1 FROM DUAL
    14  UNION
    15  SELECT 9 COL1 FROM DUAL
    16  UNION
    17  SELECT 10 COL1 FROM DUAL
    18  UNION
    19  SELECT 13 COL1 FROM DUAL
    20  UNION
    21  SELECT 14 COL1 FROM DUAL
    22  UNION
    23  SELECT 15 COL1 FROM DUAL
    24  UNION
    25  SELECT 16 COL1 FROM DUAL
    26  UNION
    27  SELECT 23 COL1 FROM DUAL
    28  UNION
    29  SELECT 24 COL1 FROM DUAL
    30  )
    31  SELECT OUTPUT FROM
    32  (
    33  SELECT DECODE(COL3,NULL,COL1, COL2)  || '-' || LEAD(DECODE(COL3,NULL,COL3, COL1)) OVER (ORDER BY DECODE(COL3,NULL,COL1, COL2)) OUTPUT  FROM
    34  (
    35  SELECT COL1, LEAD(COL1) OVER (ORDER BY COL1) COL2, LAG(COL1) OVER (ORDER BY COL1) COL3 FROM T
    36  )
    37  WHERE
    38  (COL2 - COL1 > 1 OR COL2 IS NULL OR COL3 IS NULL)
    39  )
    40  WHERE OUTPUT != '-';
    OUTPUT                                                                         
    1-5                                                                            
    8-10                                                                           
    13-16                                                                          
    23-24

  • Urgent Help required in Tunning this query

    I have table ACCOUNT SPONSOR HOMESTORE ASH with more than 30 million rows.
    My batch daily need to update or insert into this table from a temporary table TEMP_HSTRALCT. The data for temporary table is populated by below query which selects from two tables TRANSACTION POINTS and REDEMPTIONS.However both these tables are partitioned on date time and is run daily and this is running for hours.
    Can anyone please help me on tuning this query
    INSERT INTO temp_hstralct
    (tmp_n_collector_account_num, tmp_v_location_id,
    tmp_v_sponsor_id, tmp_v_source_file_name,
    tmp_n_psc_insert_ind, tmp_n_psc_update_ind,
    tmp_n_transaction_amount, tmp_n_transaction_points,
    tmp_n_acc_insert_ind, tmp_n_ash_insert_ind,
    tmp_n_col_insert_ind, tmp_n_check_digit,
    tmp_n_collector_issue_num, tmp_n_csl_insert_ind,
    tmp_v_offer_code, tmp_n_psa_insert_ind)
    SELECT DISTINCT trp_n_collector_account_num account_num,
    trp_v_location_id location_id,
    trp_v_sponsor_id sponsor_id,
    trp_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM transaction_points, ACCOUNT, locations_master,homestores
    WHERE hsr_v_accrual_allowed = 'Y'
    AND trp_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND trp_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND trp_v_sponsor_id = 'JSAINSBURY'
    AND trp_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id = 'JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    UNION ALL
    SELECT DISTINCT rdm_n_collector_account_num account_num,
    rdm_v_location_id location_id,
    rom_v_supplier_id sponsor_id,
    rdm_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM redemption_details,
    reward_offer_master,
    ACCOUNT,
    locations_master,
    HOMESTORES
    WHERE hsr_v_redemption_allowed = 'Y'
    AND rdm_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND rdm_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND rom_v_reward_offer_id = rdm_v_reward_id
    AND rom_v_supplier_id = 'JSAINSBURY'
    AND rdm_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id ='JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    );

    I have copied the explain as it is and can you please try pasting in the text pad.Can you let me know whether parallel hint on this will speed up the select queries.
              Plan
              INSERT STATEMENT CHOOSECost: 410,815 Bytes: 2,798,394 Cardinality: 15,395                                                        
                   32 UNION-ALL                                                   
                        15 SORT UNIQUE Cost: 177,626 Bytes: 2,105,592 Cardinality: 11,896                                              
                             14 FILTER                                         
                                  13 HASH JOIN Cost: 177,312 Bytes: 2,105,592 Cardinality: 11,896                                    
                                       2 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 23,184 Cardinality: 966                               
                                            1 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 1                          
                                       12 FILTER                               
                                            11 HASH JOIN OUTER                          
                                                 8 MERGE JOIN CARTESIAN Cost: 155,948 Bytes: 702,656,660 Cardinality: 4,845,908                     
                                                      3 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1                
                                                      7 BUFFER SORT Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908                
                                                           6 PARTITION RANGE ITERATOR Partition #: 12           
                                                                5 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.TRANSACTION_POINTS Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908 Partition #: 12      
                                                                     4 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_TRANSACTION_POINTS_1 Cost: 24,880 Cardinality: 6,978,108 Partition #: 12
                                                 10 PARTITION RANGE ALL Partition #: 15 Partitions accessed #1 - #5                    
                                                      9 TABLE ACCESS FULL LMHOLTP.ACCOUNT Cost: 6,928 Bytes: 68,495,680 Cardinality: 8,561,960 Partition #: 15 Partitions accessed #1 - #5               
                        31 SORT UNIQUE Cost: 233,189 Bytes: 692,802 Cardinality: 3,499                                              
                             30 FILTER                                         
                                  29 FILTER                                    
                                       28 NESTED LOOPS OUTER                               
                                            24 HASH JOIN Cost: 226,088 Bytes: 664,810 Cardinality: 3,499                          
                                                 16 TABLE ACCESS FULL LMHOLTP.REWARD_OFFER_MASTER Cost: 8 Bytes: 2,280 Cardinality: 114                     
                                                 23 HASH JOIN Cost: 226,079 Bytes: 8,327,280 Cardinality: 48,984                     
                                                      20 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 432 Cardinality: 18                
                                                           19 NESTED LOOPS Cost: 39 Bytes: 2,304 Cardinality: 18           
                                                                17 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1      
                                                                18 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 966      
                                                      22 PARTITION RANGE ITERATOR Partition #: 28                
                                                           21 TABLE ACCESS FULL LMHOLTP.REDEMPTION_DETAILS Cost: 226,019 Bytes: 261,636,270 Cardinality: 6,229,435 Partition #: 28           
                                            27 PARTITION RANGE ITERATOR Partition #: 30                          
                                                 26 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.ACCOUNT Cost: 2 Bytes: 8 Cardinality: 1 Partition #: 30                     
                                                      25 INDEX UNIQUE SCAN UNIQUE LMHOLTP.CO_PK_ACCOUNT Cost: 1 Cardinality: 1 Partition #: 30

  • Help required in writing an sql to fetch the the difference of the data.

    Hi Gurus,
    Could some one help me in writing an sql to pull data the difference between two same structured tables from two different database and to store that data in an temperory table.
    many many thanks in advance

    Lets say you have two db SOURCE and DEST
    SOURCE is the DB that you have Logged in into. Now you do the following.
    1. Createa DBLink to DEST database.
    2. Check if the DBLink works properly.
    3. Then execute the following sql.
    select <column_list> from <table_name>
    minus
    select <column_list> from <table_name>@<dblink>
    union all
    select <column_list> from <table_name>@<dblink>
    minus
    select <column_list> from <table_name>

  • Help required in writing And Reading Xml From Database

    Hi
    i m new to java.
    i m facing problem while writing Xml file from Mysql Database in java i m using the WebRowSet
    and also for Reading WebRowSet
    after reading the Xml i have to save this in Database
    (required source code)
    is there any one to help me in this way
    regards
    aamir

    shadab_think_globally wrote:
    {noformat}*hi everybody,
    please send me a ajax with jsp application
    suppose i enter a word in text area ajax will populate/suggest all string from database ,who started
    from that entering character(s).like a google string search.
    please send full source code
    *{noformat}how about you do it yourself?

  • Help required in refining a query

    I have a sql query :
    select C1 AS No_Of_Completed_WOs, C2 as Wos_with_Soft_Fail, (C1-C2) as Completed_Wos,C3 as Failed_Wos,C4 as TimedOut_Wos from (select (CASE WHEN TBL_WRK_ORD.EXTSYS_ID IS NULL THEN '<NULL>'
    ELSE TBL_WRK_ORD.EXTSYS_ID END),
    count(case when WO_STAT=104 AND XACTION_TYPE like '%Completion%' then WO_STAT end ) as C1,
    count(case when WO_STAT=104 AND XACTION_TYPE like '%Soft Error%' then WO_STAT end ) AS C2,
    count(case when WO_STAT=253 then WO_STAT end ) AS C3,
    count(case when WO_STAT=251 then WO_STAT end ) AS C4
    from TBL_WRK_ORD,TBL_WO_EVENT_QUEUE WHERE TBL_WRK_ORD.WO_ID=TBL_WO_EVENT_QUEUE.WO_ID group by TBL_WRK_ORD.EXTSYS_ID)
    The query basically maintains a separate counter for each of the qualifying condition.
    C1 : if the WO_STAT is 104 and XACTION_TYPE is '%Completion%'
    C2 : if the WO_STAT is 104 and XACTION_TYPE is '%Soft Error%'
    C3 : if the WO_STAT is 253
    C4 : if the WO_STAT is 251.
    Now, the requirement is that we need to fetch distinct records, based on which the summation will be carried upon.
    I was not able to incorporate the "distinct" logic in the above query.
    Required help in this regards, as how to fetch distinct records and use it in the summation logic.
    A quick help would be appreciated and thankful.
    Regards
    RAT.
    Edited by: user9546298 on Feb 24, 2010 6:36 AM
    Edited by: user9546298 on Feb 24, 2010 7:06 AM

    Here is the sample data :
    {code }
    Table : TBL_WRK_ORD
    WO_ID SCHED_DTS WO_STAT
    EXTSYS_ID
    A00000001-QRY_ISUP_SERVICE_L 20091126 03:28:02 103
    MRK
    A00000002-S3 20091201 02:42:34 255
    MRK
    A00000003-A4 20091201 02:50:28 253
    A00000006-ADD1 20091202 05:37:45 104
    A00000004-ADD1 20091201 03:40:39 104
    A00000005-DNH1 20091202 05:12:06 253
    6 rows selected.
    Table : TBL_WO_EVENT_QUEUE
    WO_ID XACTION_TYPE
    A00000001-QRY_ISUP_SERVICE_L WO Accept
    A00000001-QRY_ISUP_SERVICE_L WO Startup
    A00000001-QRY_ISUP_SERVICE_L WO Completion
    A00000002-S3 WO Accept
    A00000003-A4 WO Accept
    A00000003-A4 WO Startup
    A00000003-A4 WO Rollback
    A00000003-A4 WO Failure
    A00000005-DNH1 WO Rollback
    A00000005-DNH1 WO Failure
    A00000006-ADD1 WO Accept
    A00000006-ADD1 WO Startup
    A00000004-ADD1 WO Accept
    A00000004-ADD1 WO Startup
    A00000004-ADD1 WO Completion
    A00000005-DNH1 WO Accept
    A00000005-DNH1 WO Startup
    A00000006-ADD1 WO Completion
    Current output :
    NO_OF_COMPLETED_WOS WOS_WITH_SOFT_FAIL COMPLETED_WOS FAILED_WOS TIMEDOUT_WOS
    2 0 2 8 0
    0 0 0 0 0
    Here, as you can see above that the result has duplicates, which caused the counters to show wrong result.
    Now, the query should filter based on given criteria and produce the count of the filtered rows.
    But doing so, should consider distinct rows for counting.
    Also, just placing distinct at counting logic [ pasted by you ] didnot work. I tried it out, but in vain.
    Regards
    RAT.
    Edited by: user9546298 on Feb 24, 2010 7:09 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help needed in writing a query

    Hi all,
    Following is the structure of my table.
    Data
    Key Number
    Id Number
    Value varchar2(100)
    activity_name varchar2(100)
    Creation_Date Date
    Eval_Point varchar2(100)
    In the above table Id is the primary key.
    The column eval_point holds only two types of entries 'activation' or 'completion'
    The activity_name column holds the name of the activity.
    The sample entries in the table are as follows
    Key Value activity_name Creation_Date Id Eval_Point
    260002 XXX assign_1 2007-09-21 16:58:41.920000 951 activation
    260002     XXX assign_1 2007-09-21 16:58:43.392000 953     completion
    260002     XXX assign_2 2007-09-21 16:59:03.732000 956     activation
    260002     XXX assign_2 2007-09-21 16:59:04.112000 954     completion
    260002     XXX assign_3 2007-09-21 16:59:24.331000     958     activation
    260002     XXX assign_3 2007-09-21 16:59:24.421000     957     completion
    i need to write a query which gives me data in the following format
    value id start_date end_date
    XXX YYY 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000
    where start_date is the creation date of the 'activation' and end_date is the creation_date of 'completion'.
    Can somebody help?
    -thanks
    lavanya

    hello all,
    I would like to re frame my question.
    this is the output of the base query
    select id,instance_key,sensor_target,activity_sensor,creation_date,eval_point from bpel_variable_sensor_values where instance_key=260002;
    953     260002     Assign_1     952     2007-09-21 16:58:43.392000     completion
    951     260002     Assign_1     952     2007-09-21 16:58:41.920000     activation
    956     260002     Assign_2     955     2007-09-21 16:59:03.732000     activation
    954     260002     Assign_2     955     2007-09-21 16:59:04.112000     completion
    958     260002     Assign_3     959     2007-09-21 16:59:24.331000     activation
    957     260002     Assign_3     959     2007-09-21 16:59:24.421000     completion
    962     260002     Assign_4     960     2007-09-21 16:59:44.741000     completion
    961     260002     Assign_4     960     2007-09-21 16:59:44.640000     activation
    964     260002     Assign_5     965     2007-09-21 17:00:05.290000     completion
    963     260002     Assign_5     965     2007-09-21 17:00:04.950000     activation
    I am trying out this query
    select a.instance_key,a.creation_date,b.creation_date,a.id
    from bpel_variable_sensor_values a, bpel_variable_sensor_values b
    where a.instance_key=b.instance_key
    and a.instance_key=260002
    and a.eval_point='activation'
    and b.eval_point='completion'
    and i am getting 25 entries i.e a cartesian product of a.creation_date
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:58:43.392000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:04.112000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:24.421000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:44.741000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 17:00:05.290000     951
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:58:43.392000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:04.112000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:24.421000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:44.741000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 17:00:05.290000     956
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:58:43.392000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:04.112000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:24.421000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:44.741000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 17:00:05.290000     958
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:58:43.392000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:04.112000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:24.421000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:44.741000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 17:00:05.290000     961
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:58:43.392000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:04.112000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:24.421000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:44.741000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 17:00:05.290000     963
    can soembody help me to reduce these to 5 rows.

  • Help me in writing this query  plz....

    There are two tables - Table1 (table1_id, value1) and Table2 (table2_id,
    table1_id, value2). The field Table2.table1_id is a foreign key to
    Table1.table1_id. It is necessary to write a SQL query that would find
    all records in Table1 that do not have a corresponding record in Table2.
    The query should not use sub-selects

    user554495 wrote:
    Can you provide me the queryNo, we're not about to do your homework for you. How do you expect to learn anything if all the answers are served to you on a silver platter?
    Try and work it out for yourself; if you get stuck, we'll try and help from that point, but you'd have to provide the sql queries you've tried (along with table information and sample input and expected output data).

  • Help required in optimizing the query response time

    Hi,
    I am working on a application which uses a jdbc thin client. My requirement is to select all the table rows in one table and use the column values to select data in another table in another database.
    The first table can have maximum of 6 million rows but the second table rows will be around 9000.
    My first query is returning within 30-40 milliseconds when the table is having 200000 rows. But when I am iterating the result set and query the second table the query is taking around 4 millisecond for each query.
    the second query selection criteria is to find the value in the range .
    for example my_table ( varchar2 column1, varchar2 start_range, varchar2 end_range);
    My first query returns a result which then will be used to select using the following query
    select column1 from my_table where start_range < my_value and end_range> my_value;
    I have created an index on start_range and end_range. this query is taking around 4 millisseconds which I think is too much.
    I am using a preparedStatement for the second query loop.
    Can some one suggest me how I can improve the query response time?
    Regards,
    Shyam

    Try the code below.
    Pre-requistee: you should know how to pass ARRAY objects to oracle and receive resultsets from java. There are 1000s of samples available on net.
    I have written a sample db code for the same interraction.
    Procedure get_list takes a array input from java and returns the record set back to java. You can change the tablenames and the creteria.
    Good luck.
    DROP TYPE idlist;
    CREATE OR REPLACE TYPE idlist AS TABLE OF NUMBER;
    CREATE OR REPLACE PACKAGE mypkg1
    AS
       PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor);
    END mypkg1;
    CREATE OR REPLACE PACKAGE BODY mypkg1
    AS
       PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor)
       AS
          ctr   NUMBER;
       BEGIN
          DBMS_OUTPUT.put_line (myval_list.COUNT);
          FOR x IN (SELECT object_name, object_id, myvalue
                      FROM user_objects a,
                           (SELECT myval_list (ROWNUM + 1) myvalue
                              FROM TABLE (myval_list)) b
                     WHERE a.object_id < b.myvalue)
          LOOP
             DBMS_OUTPUT.put_line (   x.object_name
                                   || ' - '
                                   || x.object_id
                                   || ' - '
                                   || x.myvalue
          END LOOP;
       END;
    END mypkg1;
    [pre]
    Testing the code above. Make sure dbms output is ON.
    [pre]
    DECLARE
       a      idlist;
       refc   sys_refcursor;
       c number;
    BEGIN
       SELECT x.nu
       BULK COLLECT INTO a
         FROM (SELECT 5000 nu
                 FROM DUAL) x;
       mypkg1.get_list (a, refc);
    END;
    [pre]
    Vishal V.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help required in writing PCR's

    Hi All,
    Update on this is highly appreciable and points will be rewarded.
    Thanks & Regards,
    surya
    Hi All,
    To calculate OT as per the Client requirement two PCR's needs to be wriiten.
    1. OT should not be paid if it is less than 30 mins.
    2. OT should be calculated as follows:
    (basic2/26/8no. of hours).
    Your help in this regard is highly appreciable.
    Thanks & Regards,
    Surya
    Edited by: Surya Prakash Kanuru on Sep 15, 2008 9:55 AM

    Hi,
          No need to write to 2  PCR ,with one pcr itself it can be calculated . Here maintain  overtime hrs in 15 infotype ,such that overtime hrs will be  stored in a wage type say 9ovt . 
    Pcr can be build in this way
    90vt
    num = 90vt(where overtime hrs will be transfered to num)
    num?0.5
    < ( if the hrs is 30 mins )
    your logic
    = (30 mins )
    logic calc
    >  (30 min)
    amt = 1001 (basic wage type)
    amt = 1001 div 2
    some calc
    div ana (for dividing with the no of hrs and passing the overtime value to the amt)
    addwt *
    Hope it helps u
    Regards,
    Prince Elvis

  • Help required in writing UDF

    Hi SDNers,
    I have a requirement to write UDF, can anybody help me in acheiving the code.
    Requirement:-
    If I am getting 5 as my input to UDF, I need to generate five 001's to my output of UDF.
    I tried to loop the input and used result.addValue("001"); but not working.
    Please help in getting java logic for this udf.
    Thanks
    Jayaram.G

    Hi Luis,
    Thanks for your quick response.
    I am using context in my udf.
    My code is like this.
    for(int i=0;i<var1.length;i++)
    result.addValue("001");
    As I am getting 5 as input and I am using Var1.length, the udf is generating only one 001. But I need five 001.
    Regards,
    Jayaram.G

  • Pls help me in writing a query for my problem !

    I have to find out the amount(LAmt) for members who lie btw diff age groups, below are the table structures:
    table1
    DOB ID
    12/24/1986 F125
    06/05/1988 F223
    05/04/1987 F589
    07/07/2001 F856
    table2
    LAmt ID LDate
    $56 F125 01/01/2011
    $45 F223 08/22/2005
    $87 F589 09/24/2004
    $87 F856 10/10/2000
    $87 F587 09/09/2002
    Query:
    1) I have to find the age group for the members who lie between 1 to 5 & 6 to 10 and so on, Also find the the no. of days since they have been registered(Using LDate-Current Date) , also the LAmt for those members.

    Hi,
    836810 wrote:
    SELECT -- To calculate Listed Amount of members btw age group 0 to 4
    COUNT(DateOfBirth) as Nopresent,
    DATEDIFF (yyyy,DateOfBirth,GETDATE()) as age,
    SUM(RPTInvHosp.AccountListAmount) as ListedAmt,
    COUNT(DateOfBirth) * SUM(RPTInvHosp.AccountListAmount) as [Calc]
    FROM RPTInv1st,RPTInvHosp
    WHERE
    DATEDIFF (yyyy,DateOfBirth,GETDATE()) >= 0 and
    DATEDIFF (yyyy,DateOfBirth,GETDATE()) < 5 and
    RPTInv1st.PASDebtorID=RPTInvHosp.PASDebtorID
    Group by DATEDIFF (yyyy,DateOfBirth,GETDATE())
    I want to get members btw the particular age group JOIN with the no of days they have been opened an account & their amount.In Oracle, use double-quotes (or nothing) instead of square brackets around aliases:
    COUNT(DateOfBirth) * SUM(RPTInvHosp.AccountListAmount)  as "Calc"The double-quotes are only necessary if you want the alias not to conform to the normal naming conventions; they are optional around normal names, such as CALC.
    There are no built-in functions called GETDATE or DATEDIFF in Oracle.
    In Oracle, SYSDATE returns the current DATE (on the database server).
    There's nothing very convenient in Oracle for getting the difference between two DATEs in units of a year. The best way is to use MONTHS_BETWEEN to get the difference in months, and then divide that number by 12, like this:
    WHERE     FLOOR ( MONTHS_BETWEEN ( SYSDATE
                                , DateOfBirth
               / 12
               )          BETWEEN     0
                         AND     4Do you need help about how to do a join?
    It's not at all clear what you want here.
    Whenever you have a question, post CREATE TABLE and INSERT statements for your sample data, and post the exact results you want from that data. Explain, with specific examples, how you get those results from that data.
    Always say what version of Oracle (or other software) you're using.

  • Help required in writing an sql querry

    Hi guys,
    Could any one hlep me out in writing an sql querry for the below requirement.
    the requirement is: for a perticular ID if we have different names then we need to get it out as multiple else the name itselef. I have given the sample input and the expected output.
    ID Name
    1 A
    1 B
    2 F
    2 F
    3 C
    4 D
    4 E
    Out put should look like
    ID Name
    1 Multiple
    2 F
    3 C
    4 Multiple
    Thanks in advance
    Shylender.
    Edited by: 959345 on Nov 22, 2012 10:13 PM

    May be this:
    WITH t AS
            (SELECT 1 id, 'A' str FROM DUAL
             UNION ALL
             SELECT 1, 'B' FROM DUAL
             UNION ALL
             SELECT 2, 'F' FROM DUAL
             UNION ALL
             SELECT 2, 'F' FROM DUAL
             UNION ALL
             SELECT 3, 'C' FROM DUAL
             UNION ALL
             SELECT 4, 'D' FROM DUAL
             UNION ALL
             SELECT 4, 'E' FROM DUAL),
         t1 AS
            (SELECT id,
                    CASE
                       WHEN COUNT (DISTINCT str) OVER (PARTITION BY id) > 1 THEN
                          'MULTIPLE'
                       ELSE
                          str
                    END
                       str
               FROM t)
      SELECT id, str
        FROM t1
    GROUP BY id, str
    ORDER BY 1;Cheers,
    Manik.

  • Help with re-writing this query

    Dear experts;
    create table t2
      ID varchar2(1000),
      name varchar2(1000),
       place varchar2(1000)
    create table mappingt2
      grades varchar2(1000)
      individual varchar2(1000)
    insert into t2 values ('James', 'John', 'newyork');
    insert into t2 values ('Linda', 'James', 'London');
    insert into t2 values ('Alex', 'kim', 'Mexico');
    insert into t2 values ('karen', 'Jack', 'Tunis');
    insert into t2 values ('CC', 'Jack', 'Peru');
    insert into t2 values ('Linda', 'James', 'Germany');
    insert into mappingt2 values ('A', 'James');
    insert into mappingt2 values ('C', 'Kim');
    insert into mappingt2 values ('C', 'Linda');
    insert into mappingt2 values ('B', 'CC');I have the following query below
    SELECT (select grades from mappingt2 t
       where t.individual =  pt.ID) as current_grade
          ,(select grades from mappingt2 ty
       where ty.individual =  pt.name) alt_grade
          ,pt.place
      FROM t2 ptI was just wondering whether this query can be better written. All help is appreciated. Thank you

    user13328581 wrote:
    Hi Frank, Tom Kyte claims sub scalar queries is usually betterHe didn't say usually he said if you want the first row faster
    >
    if your goal is to optimize your query for initial response time, you may want to use the former query, with the scalar subquery, because Oracle Database would have to get just the first row from DEPT, run the scalar subquery (select count...) against EMP to get the count, and then return it. The process for returning that first row would be very fast.
    >
    The corollary to this that was not explicitly mentioned in the article that I can see is that this probably comes at the expense of the time taken to return all the rows which can then take longer.

Maybe you are looking for

  • WITH CLAUSE in SPARQL - Running SPARQL query using JENA

    Hi, Can anybody help me how to use WITH Clause in SPARQL. Below is my Query. I am using Jena 2.6.3 to Run my Query. "PREFIX assc: <http://www./.../> " + "WITH " +      "( " +                     " select ?associate" +                     " where {?as

  • How to loop through Multiple Excel sheets and load them into a SQL Table?

    Hi , I am having 1 excel sheet with 3 worksheet. I have configured using For each loop container and ADO.net rowset enumerator. Every thing is fine, but after running my package I am getting below error [Excel Source [1]] Error: SSIS Error Code DTS_E

  • Problem with Point-Array

    I made the following method: Point[] makeLine (int length)           Point[] newLine = new Point[length];           for (int i = 0; i < newLine.length; i++)                newLine.x = i;                newLine[i].y = (int)Math.round(Math.random()*5+1

  • EPrint images on A4 paper (override photo tray)

    The technical specs for ePrint clearly state that it should be possible to override the photo tray when printing images: (see here): Image files that are submitted as attachments print by default on 101.6 x 152.4 mm (4 x 6 in) photo paper from the ph

  • System not listed in url iview property

    hi all, I am creating an URL iview. In property editor of the URL iview I cannot see not even one system listed. I checked the system, its permission, it does have end user permission. Can anyone help me to view the system in the url iview property.