Date column group by 15 minute interval using SQL

I am using Oracle 9i DB, I have a large table containing several rows with following example data. Each row identifies a transaction.
Transaction_id, status, completed_date
1667050 SUCCEEDED 4-Dec-03 00:00:44
1667091 SUCCEEDED 4-Dec-03 00:05:45
6670930 SUCCEEDED 4-Dec-03 00:09:46
4359066 SUCCEEDED 4-Dec-03 00:10:46
this table consists of rows for a 24 hour day period.
I need to write a SQL query to generate a report to give me a count of transactions 24 hour period grouped into 15 minute or half hour period.
for example
count time_interval
5000 00:00:00 - 00:14:59
2345 00:15:00 - 00:29:59
and so on
I am new to SQL and so am having a hard time figuring out which function or how to group date column to achieve the end result. I would be grateful if someone could throw some suggestions.

This should help.
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:4222062043865

Similar Messages

  • Cross tab Date Column Grouping

    Hi,
    I have a cross tab in my report which displays no of tickets opened grouped by day, week or Month, grouping is done based on a parameter GroupBy, which has Day, Week, Month values
    Incident   Jun -99  Jul-99
    Priority1      10          20
    Priority2      45          23
    if user selects day or week, cross tab should display column in dd/mm/yy format, if its month, MMM-yy format.
    I have created formula which returns a date type
    GroupBy = Day then Opendate
    GroupBy = Week then opendate -dayofweek(opendate)+1
    GroupBy = date(year(opendate),month(opendate),1)
    and used this date formula as column in cross tab. I tried to format using custom date style...but its not working in cross tab.
    if I use totext to format the date formula, data will not be in sorted order...ex, its showing jul-99 before jun-99
    can anyone help?
    Thanks in Advance,
    Jyothi

    You can avoid multiple cross tabs by using the Display String expression under Field Formatting.  The expression that is entered in this field is what is displayed as the field value in the report.  Use the same logic as you are using for calculating the value, except return CStr(CurrentFieldValue, <format>), where <format> is the formatting code for the desired date format based on GroupBy.
    HTH,
    Carl

  • Oracle group by 10 minutewith  interval  using rollup

    HI,
    PLEase check the below query
    When I am trying to run this query ALONE
    Select TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''||substr(c.TIME,10,3) ||':'||
    LPAD (( TO_CHAR (c.TIME, 'MI') - MOD (TO_CHAR (c.TIME,'MI'), 10)),2,'0') slice from ILCL c
    OUPUT IA M GETTTING:
    08/07/2011 10:20
    08/07/2011 10:30
    08/07/2011 10:40
    But I run the same query in the below and using that column with group by it is throwing error in group by clause
    BECAUSE USING ROllUP
    Actually the C.time data type is timestamp
    Data base column structure:
    COLUMN DATATYPE   FORMAT-----Data loaded in the data base
    TIME ------(TIMEStTAMP) ---07-AUG-11 10.29.27.746000000 AM
    SELECT 'R' TYPE, c.date,
    substr(c.Time,27,29) am r pm,
    TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''||substr(c.TIME,10,3) ||':'||
    LPAD (( TO_CHAR (c.TIME, 'MI') - MOD (TO_CHAR (c.TIME,'MI'), 10)),2,'0') slice,
    -- TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''|| substr(c.TIME,10,6) time_slice,
    CASE
    WHEN type1 = 'py'
    THEN 'pyS'
    WHEN type1 = 'PV'
    THEN 'PV'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    THEN 'pmg'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    THEN 'ACT'
    END CT,
    CASE
    WHEN type1 = 'py'
    AND e.type2 = 'EFAUOT'
    THEN 'EFAUTO'
    WHEN type1 = 'py'
    AND e.type2 = 'CA_AUTO'
    THEN 'CARD_AUTOFILL'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-CHANGED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-REMOVED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NULL
    THEN 'p_added'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type = 'H'
    THEN 'ACT_TECH'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type <> 'H'
    THEN 'A_cR'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'N'
    THEN 's_iL'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'Y'
    THEN 'spkg'
    ELSE type2
    END type2,
    CASE
    WHEN event_status_type = 'scss'
    THEN 'scss'
    ELSE 'FL'
    END STS_type,
    COUNT (DISTINCT e.ce),
    ROUND (AVG (e.elapsed_msec) / 1000) txn_time,
    ROUND (AVG (c.elapsed_msec)/1000) call_time
    FROM
    ---ivr_transaction h,
    ILC1 e,
    ILCL c,
    ILEW w,
    ILEp p
    WHERE
    ---e.CD = h.CD
    w.CD(+) = e.CD
    -- AND w.event_id(+) = e.event_id
    AND p.CD(+) = e.CD
    ---- AND p.event_id(+) = e.event_id
    AND p.ce(+) = e.ce
    AND w.ce(+) = e.ce
    AND c.CD = e.CD
    AND c.ci = e.ci
    --AND e.ce = h.ce
    AND e.CD = TRUNC (SYSDATE - 1)
    AND c.TIME <> TRUNC (SYSDATE)
    AND ( (e.type1 = 'py')
    OR (type1 = 'PV')
    OR ( type1 = 'pmg'
    AND e.type2 = 'mfy'
    OR (type1 = 'epmt'
    AND e.type2 = 'AT'
    GROUP BY 'TCR',
    c.CD,
    substr(c.TIME,27,29),
    TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''||substr(c.TIME,10,3) ||':'||
    LPAD (( TO_CHAR (c.TIME, 'MI') - MOD (TO_CHAR (c.TIME,'MI'), 10)),2,'0'),
    --TO_CHAR (c.TIME, 'MI'),
    CASE
    WHEN type1 = 'py'
    THEN 'pyS'
    WHEN type1 = 'PV'
    THEN 'PV'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    THEN 'pmg'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    THEN 'ACT'
    END,
    ROLLUP (CASE
    WHEN type1 = 'py'
    AND e.type2 = 'EFAUOT'
    THEN 'EFT_AUTO'
    WHEN type1 = 'py'
    AND e.type2 = 'CA_AUTO'
    THEN 'CARD_AUTOFILL'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-CHANGED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-REMOVED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list1 IS NOT NULL
    AND list1 IS NULL
    THEN 'p_added'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type = 'H'
    THEN 'ACT_TECH'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type <> 'H'
    THEN 'A_cR'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'N'
    THEN 's_iL'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'Y'
    THEN 'sp'
    ELSE type2
    END),
    ROLLUP (
    CASE
    WHEN event_status_type = 'scss'
    THEN 'scss'
    ELSE 'FL'
    END)
    WHEN I A M TRYING T TO EXCUTE ABOVE QUERY IT SHOING ERROR AT GEOUP BY CLAUSE AS HIGHLITED SAYS (ORA00900------Invalid sql statement) when I cooment one of the roll up sin group by clause it is getting the data but need to have two rollups all case statements are working fine no issues with those on problem with highlited ones or in the bold.Please give me sugeestions ASAP
    Thanks
    Satya

    Hi Kulash,
    Very very Thanks for the quick reply .
    SELECT     SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
         , 1
         , 15
         ) || '0'          AS slice
    FROM     dual;
    This query works fine if we run individually but the same is not runing in the group by clause
    Hi Kulash,
    Very very Thanks for the quick reply .
    SELECT     SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
         , 1
         , 15
         ) || '0'          AS slice
    FROM     dual;
    This query works fine if we run individually but the same is not runing in the group by clause .i think because of the rollups . could you pleasae tell me is there any change needed in the group by clause if we are using rollups.Because it showing error in the group by clause as a Invalid sql statement (ora00900)
    group by
    c.CD,
    substr(c.TIME,27,29),
    SUBSTR ( TO_CHAR (c.time, 'MM/DD/YYYY HH24:MI')
         , 1
         , 15
         ) || '0'
    CASE
    WHEN type1 = 'py'
    THEN 'pyS'
    WHEN type1 = 'PV'
    THEN 'PV'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    THEN 'pmg'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    THEN 'ACT'
    END,
    ROLLUP (CASE
    WHEN type1 = 'py'
    AND e.type2 = 'EFAUOT'
    THEN 'EFT_AUTO'
    WHEN type1 = 'py'
    AND e.type2 = 'CA_AUTO'
    THEN 'CARD_AUTOFILL'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-CHANGED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-REMOVED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list1 IS NOT NULL
    AND list1 IS NULL
    THEN 'p_added'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type = 'H'
    THEN 'ACT_TECH'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type 'H'
    THEN 'A_cR'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'N'
    THEN 's_iL'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'Y'
    THEN 'sp'
    ELSE type2
    END),
    ROLLUP (
    CASE
    WHEN event_status_type = 'scss'
    THEN 'scss'
    ELSE 'FL'
    END)
    ---------------------------TOTAL QUERY----------------------------
    SELECT 'R' TYPE, c.date,
    substr(c.Time,27,29) am r pm,
    SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
         , 1
         , 15
         ) || '0' slice,
    CASE
    WHEN type1 = 'py'
    THEN 'pyS'
    WHEN type1 = 'PV'
    THEN 'PV'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    THEN 'pmg'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    THEN 'ACT'
    END CT,
    CASE
    WHEN type1 = 'py'
    AND e.type2 = 'EFAUOT'
    THEN 'EFAUTO'
    WHEN type1 = 'py'
    AND e.type2 = 'CA_AUTO'
    THEN 'CARD_AUTOFILL'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-CHANGED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-REMOVED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NULL
    THEN 'p_added'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type = 'H'
    THEN 'ACT_TECH'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type 'H'
    THEN 'A_cR'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'N'
    THEN 's_iL'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'Y'
    THEN 'spkg'
    ELSE type2
    END type2,
    CASE
    WHEN event_status_type = 'scss'
    THEN 'scss'
    ELSE 'FL'
    END STS_type,
    COUNT (DISTINCT e.ce),
    ROUND (AVG (e.elapsed_msec) / 1000) txn_time,
    ROUND (AVG (c.elapsed_msec)/1000) call_time
    FROM
    ---ivr_transaction h,
    ILC1 e,
    ILCL c,
    ILEW w,
    ILEp p
    WHERE
    ---e.CD = h.CD
    w.CD(+) = e.CD
    -- AND w.event_id(+) = e.event_id
    AND p.CD(+) = e.CD
    ---- AND p.event_id(+) = e.event_id
    AND p.ce(+) = e.ce
    AND w.ce(+) = e.ce
    AND c.CD = e.CD
    AND c.ci = e.ci
    --AND e.ce = h.ce
    AND e.CD = TRUNC (SYSDATE - 1)
    AND c.TIME TRUNC (SYSDATE)
    AND ( (e.type1 = 'py')
    OR (type1 = 'PV')
    OR ( type1 = 'pmg'
    AND e.type2 = 'mfy'
    OR (type1 = 'epmt'
    AND e.type2 = 'AT'
    GROUP BY 'TCR',
    c.CD,
    substr(c.TIME,27,29),
    SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
         , 1
         , 15
         ) || '0',
    --TO_CHAR (c.TIME, 'MI'),
    CASE
    WHEN type1 = 'py'
    THEN 'pyS'
    WHEN type1 = 'PV'
    THEN 'PV'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    THEN 'pmg'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    THEN 'ACT'
    END,
    ROLLUP (CASE
    WHEN type1 = 'py'
    AND e.type2 = 'EFAUOT'
    THEN 'EFT_AUTO'
    WHEN type1 = 'py'
    AND e.type2 = 'CA_AUTO'
    THEN 'CARD_AUTOFILL'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NOT NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-CHANGED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list IS NULL
    AND remove_from_service_code_list IS NOT NULL
    THEN 'pmg-REMOVED'
    WHEN type1 = 'pmg'
    AND e.type2 = 'mfy'
    AND list1 IS NOT NULL
    AND list1 IS NULL
    THEN 'p_added'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type = 'H'
    THEN 'ACT_TECH'
    WHEN type1 = 'epmt'
    AND e.type2 = 'AT'
    AND c.campaign_type 'H'
    THEN 'A_cR'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'N'
    THEN 's_iL'
    WHEN type1 = 'PV'
    AND type2 = 'SPORT'
    AND p.flag = 'Y'
    THEN 'sp'
    ELSE type2
    END),
    ROLLUP (
    CASE
    WHEN event_status_type = 'scss'
    THEN 'scss'
    ELSE 'FL'
    END)

  • Problems with DATE columns in 9.2.0.4 using JDBC

    In Oracle 9.2.0.4.0, it seems Oracle has yet again altered the way it JDBC drivers return Oracle DATE columns. These columns now only refer to date information; the Oracle type TIMESTAMP now is used to contain date and time information. Since my application does not support java.sql.Date, it is reporting that some columns cannot be populated, because the type is unsupported.
    Is there anyway that I can get my Oracle DATE columns to return java.sql.Timestamp objects ?
    This seems like a bug on Oracle's part--we have a column that stores date and time data (an Oracle DATE column), and the Oracle JDBC driver tells us that the column only stores a date (it reports it as java.sql.Date).
    I am using oracle.jdbc.OracleDriver.
    Thanks,
    Amit

    did you migrate the database or just install the 9.2.0.8 software?
    After database upgrade, your database and the software should have the same version:
    <i><b>select version from v$instance</b></i>; (software version)
    <i><b>select comp_id,version,status from dba_registry;[/</b>i] (database version)
    How are the environment settings of <sid>adm?
    Run please R3trans -d or R3trans -x and post the trans.log.  Could you please also check the developer traces, if there are any other errors?
    Best regards
    Baran

  • How can I group student scores into quintile using SQL Server 2008

    Can anyone help me to group student scores into quintile. I think there is a feature in SQL Server 2012, but still we are have not upgrade to it as we are using 2008R2. I tried Ntile(5) but it not generating the desired result. I need below Quintile column
    Student Score Quintile
    Student1 20 1
    Student2 20 1
    Student3 30 2
    Student4 30 2
    Student5 40 2
    Student6 40 2
    Student7 50 3
    Student8 50 3
    Student9 60 3
    Student10 70 4
    Student11 70 4
    Student12 80 4
    Student13 80 4
    Student14 90 5

    Please try to get ranking for below data
    HI , I need a dynamic SQL which would handle few hundred records and scores may vary..Sometime it may be small test marks ranging from 5 to 25 sometimes it may be out of 100. 
    I tried for larger data set. It
    failed. It is not at all showing Rank 3.Since it not falling in the comparison Below are the 99 records.
    Student
    Name  -> Score
    Student
    1 to 5 -> 4
    Student
    7 to 26 -> 5
    Student
    27 to 71 -> 6
    Student
    72 to 98 -> 7
    Student
    99 -> 9

  • Extract Data from XML and Load into table using SQL*Loader

    Hi All,
    We have a XML file (sample.xml) which contains credit card transaction information. We have a standard SQL*Loader control file which loads the data from a flat file and the control file code is written as position based method. Our requirement is to use this control file as per our requirement(i.e) load the data into the table from our XML file), But we need help in converting the XML to a flat file or Extract the data from the XML tags and pass the information to the control file and in turn it loads the table.
    Your suggestion is highly appreciated.
    Thanks in advance

    Hi,
    First of all go to PSA maintanance ( Where you will see PSA records ).
    Goto list---> Save-> File---> Spreadsheet (Choose Radio Button)
    > Give the proper file name where you want to download and then-----> Generate.
    You will get ur PSA data in Excel Format.
    Thanks
    Mayank

  • 3.1EA1: Column Headings don't display when using SQL*Plus formatting

    The Col[umn] command doesn't show the column headings or the total lines in sqldev. This SQL command:
    -- Size per datafile
    col tablespace_name format a10 head 'Tablespace'
    col file_name format a40 head DataFileName
    col cursize form 999.99 head "CurrSize|GB"
    col maxsize form 999.99 head "MaxSize|GB"
    col Autoextensible form a4 head "Auto"
    break on tablespace_name
    compute sum label Total of cursize maxsize on tablespace_name
    select tablespace_name,
    file_name,
    bytes/1024/1024/1024 cursize,
    maxbytes/1024/1024/1024 maxsize,
    autoextensible
    from dba_data_files
    where tablespace_name = 'TS_DP'
    Looks like this in sqldev:
    TS_DP /ddawno/oradata/data01/dp_data22.dbf 1.76 1.76 YES
    TS_DP /ddawno/oradata/data01/dp_data01.dbf 1.76 1.76 YES
    22 rows selected
    But looks like this in SQLPlus:
    CurrSize MaxSize
    Tablespace DataFileName GB GB Auto
    TS_DP /ddawno/oradata/data01/dp_data22.dbf 1.76 1.76 YES
    /ddawno/oradata/data01/dp_data01.dbf 1.76 1.76 YES
    Total 36.20 31.64
    22 rows selected.
    Edited by: 893982 on Nov 1, 2011 11:09 AM Fix dashed line formatting.

    Hi, thanks for the response.
    No, I do not have "set heading off" somewhere. What I pasted into my original post is the entire script that I am running from the worksheet, and I am not using a startup script.
    Odd that the column formatting works for you, yet the list of unsupported commands that you pointed me to says that col[umn] is not supported. Help column from within sqldev contradicts that documentation, showing that col[umn] is supported, but only for the "NEW_V[ALUE] syntax."
    Wow, there's nothing like enabling the most obscure keyword just to be able to say that a function is supported. Oh, well, at least the scripts that I download from the web run now. In 3.0 they died with a hard error just because the col[umn] keyword was used.

  • Getting data of two records in one line using SQL

    Hi,
    We have a COMPANY_RESEARCH table that maps companies to the Research Universes that do research on them. This table has:
    COMPANY_ID VARCHAR2(100), foreign key to COMPANY table.
    RESEARCH_UNIT_ID CHAR(1)
    Valid values for RESEARCH_UNIT_ID are 1(US Equity), 2(Canadian Equity) and 3(Debt security).
    Within my COMPANY_RESEARCH_ID table, I have:
    COMPANY_ID RESEARCH_UNIT_ID
    aaaa 2
    aaaa 3
    How can I write a SQL query that gives me the output?
    Company Id Equity Debt
    aaaa Canada Yes
    My attempt was as below:
    select
         FILTERED_COMPANIES.COMPANY_ID as Company,
         DECODE(FILTERED_COMPANIES.RESEARCH_UNIT_ID,'1','US','2','Canada','3','N/A') As Equity,
         DECODE(FILTERED_COMPANIES_1.RESEARCH_UNIT_ID,'1','N/A','2','N/A','3','Yes') as Debt
    FROM
              select distinct
              company_id, research_unit_id
              from company_research_relation
         )FILTERED_COMPANIES,
              select distinct
              company_id, research_unit_id
              from company_research_relation
         )FILTERED_COMPANIES_1
    WHERE
         FILTERED_COMPANIES.COMPANY_ID = FILTERED_COMPANIES_1.COMPANY_ID
         AND FILTERED_COMPANIES.RESEARCH_UNIT_ID = FILTERED_COMPANIES_1.RESEARCH_UNIT_ID
    but that produces output as below:
    Company Id Equity Debt
    aaaa Canada N/A
    aaaa N/A Yes
    Thanks in advance..

    Hi,
    how about this one?
    SELECT select_equity.company_id, enquity, dept, select_equity.research_unit_id, SELECT_dept.research_unit_id
    FROM
    (SELECT company_id, research_unit_id, DECODE(RESEARCH_UNIT_ID,'1','US','2','Canada','3','N/A') enquity FROM company_research) select_equity,
    (select company_id, research_unit_id, DECODE(RESEARCH_UNIT_ID,'1','N/A','2','N/A','3','Yes') Dept FROM company_research) SELECT_dept
    WHERE select_equity.company_id = SELECT_dept.company_id
    AND enquity != 'N/A'
    AND dept != 'N/A';
    Regards,
    Gerd

  • Which type of index is useful for date columns with time stamp

    Hi all,
    I am using date column in the where clause of an SQL Query. The values stored in the date column are includes timestamp. The query is very slow and there is no index on the date column.
    Can any body suggest which index is better on date columns
    Thanks

    I am using date column in the where clause of an SQL Query.Dates a re hard queries to tune. This ...
    WHERE start_date BETWEEN to_date('01-SEP-05') AND to_date('02-SEP-05')...probably requires a very different execution plan to this...
    WHERE start_date BETWEEN to_date('01-JAN-01') AND to_date('02-SEP-05')Just bunging an index on the date column may speed up your specific query but break something else. So be careful.
    Cheers, APC

  • Group by 10 minutes

    Hi all,
    Oracle 11 g
    I have the following table and data
    CREATE TABLE dummy_data (
    ID number NOT NULL
    ,test_Timestamp timestamp NOT NULL
    insert into dummy_data (id,test_TimeStamp) values (1,'08-MAR-10 09.43.30.922000000');
    insert into dummy_data (id,test_TimeStamp) values (2,'08-MAR-10 09.46.30.922000000');
    insert into dummy_data (id,test_TimeStamp) values (3,'08-MAR-10 09.23.30.922000000');
    insert into dummy_data (id,test_TimeStamp) values (4,'08-MAR-10 09.26.30.922000000');
    insert into dummy_data (id,test_TimeStamp) values (5,'08-MAR-10 09.13.30.922000000');
    insert into dummy_data (id,test_TimeStamp) values (6,'08-MAR-10 09.12.30.922000000');
    I need to get the average of id values , grouped by 10 minute interval of test_timestamp values. How can I do that ?
    For hourly grouping I did the following and it works, but not sure how to do it for 10 minute interval
    select to_char(test_Timestamp, 'yyyy-mm-dd hh24') as ts,
         avg(id) as id
         from dummy_data
         GROUP BY to_char(test_Timestamp, 'yyyy-mm-dd hh24') ;
    Thanks
    _Pete                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    And here's the explaination:
    SQL> select id,trunc (test_timestamp, 'hh24')+
      2  numtodsinterval (round (extract (minute from test_timestamp) / 5) * 5, 'minute') test_timestamp,
      3  test_Timestamp
      4  from dummy_data;
                      ID TEST_TIMESTAMP   TEST_TIMESTAMP
                       1 2010-03-08 09:45 08-MAR-10 09:43:30.922000
                       2 2010-03-08 09:45 08-MAR-10 09:46:30.922000
                       3 2010-03-08 09:25 08-MAR-10 09:23:30.922000
                       4 2010-03-08 09:25 08-MAR-10 09:26:30.922000
                       5 2010-03-08 09:15 08-MAR-10 09:13:30.922000
                       6 2010-03-08 09:10 08-MAR-10 09:12:30.922000
    6 rows selected.
    SQL> select id, trunc(to_number(to_char(test_Timestamp, 'yyyymmddhh24mi'))/5)*5 as ts,
      2  test_Timestamp
      3  from dummy_data;
                      ID                   TS TEST_TIMESTAMP
                       1         201003080940 08-MAR-10 09:43:30.922000
                       2         201003080945 08-MAR-10 09:46:30.922000
                       3         201003080920 08-MAR-10 09:23:30.922000
                       4         201003080925 08-MAR-10 09:26:30.922000
                       5         201003080910 08-MAR-10 09:13:30.922000
                       6         201003080910 08-MAR-10 09:12:30.922000
    6 rows selected.In my approach the interval 201003080910 includes from 08-MAR-10 09:10 to 08-MAR-10 09:14:59. (trunc approach)
    In your approach the interval 2010-03-08 09:10 includes from 2010-03-08 09:07:30 to 2010-03-08 09:12:29. (round approach)
    using trunc instead of round in your approach you get exactly the same results I got:
    SQL> select avg (id),
      2         trunc (test_timestamp, 'hh24')
      3         + numtodsinterval (trunc (extract (minute from test_timestamp) / 5) * 5, 'minute') test_timestamp
      4    from dummy_data
      5  group by trunc (test_timestamp, 'hh24')
      6           + numtodsinterval (trunc (extract (minute from test_timestamp) / 5) * 5, 'minute')
      7  order by test_timestamp
      8  /
                 AVG(ID) TEST_TIMESTAMP
                     5.5 2010-03-08 09:10
                       3 2010-03-08 09:20
                       4 2010-03-08 09:25
                       1 2010-03-08 09:40
                       2 2010-03-08 09:45Max
    http://oracleitalia.wordpress.com
    Edited by: Massimo Ruocchio on Mar 9, 2010 9:06 PM

  • How to use SQL*LOADER to read data in |SMITH|ALFRED| format

    the data I need to upload to table using SQL*LOADER is in format as below:
    |AD |Argentina  |
    |CN |China       |
    |US |America            |
    |GB |England        |so how should I write my control file to read the data into two columns table?
    I googled and people say that use Enclosed fields—delimiter (|), and I tried with below, but not working:
    LOAD DATA
    INFILE *
    insert
    INTO TABLE tmp_country_mapping
    FIELDS ENCLOSED BY '|'
    (country_id, country_name)
    BEGINDATA
    |AD |Argentina  |
    |CN |China       |
    |US |America            |
    |GB |England        |Anyone could help?
    BTW, I don`t want the spaces behind the value of the second column.
    Thanks
    Edited by: PhoenixBai on Dec 28, 2010 2:50 PM

    Problem solved, by removing the NLS_LANG=ENGLISH.
    >
    before the load, data is as below:
    |AD |安道尔共和国         |
    |AE |阿联酋            |
    |AF |阿富汗            |
    |AG |安提瓜和巴布达        |
    |AI |安圭拉岛           |
    |AL |阿尔巴尼亚          |after the load, data displays as below:
    AD      °2μà??12oí1ú
    AE      °¢áa??
    AF      °¢??o1
    AG      °2ìá1?oí°í2?′?
    AI      °21?à-μo
    AL      °¢??°í?á??And my database supports Chinese words and it displays correctly for other tables, except this one.
    What could be the problem?
    >
    Edited by: PhoenixBai on Dec 28, 2010 5:05 PM

  • How to transfer data from CHAR column to DATE column?

    I have a column with varchar2 data type contains data with format: dd/mm/yyyy hh24:mm:ss for example 24/11/2013 8:15:22
    I want to execute an update statement to put this data also in a date column how?
    Note: I'm using Oracle DB 10g

    BillyVerreynne wrote:
    The question you need to ask is why a date value is in a string data type?
    And the only (IMO) valid reason for that is when the presentation layer reads the value from a user's input as a string. But even in that case, the client/presentation layer should convert it to a date when binding the value, as date type, to the bind variable of the SQL (or PL/SQL) code executed.
    Dates as strings should only exist in the presentation layer.
    Well, given the OP's question/problem, it sounds like they may be in the process of trying to correct that bad design.
    On the other hand, they could simply be applying a band-aid and thereby be actually compounding the problem.
    It would be nice to get a clarification on this point from the OP.

  • Linking relational data to folders in XMLDB Repository by using metadata

    Hi,
    We want to use the XML DB Repository to store documents (PDF, Word, etc) belonging to customers, dossiers of customers, invoices of customers, etc. To accomplish this we are thinking of a folder hierarchy with the first level being customer folders, the second level dossier / invoice folders and within each of these folders the relevant documents / other folders. When querying a customer by sql, we want to determine the correct folder in the repository by storing the primary key of the customer row as user meta data to that folder. After this we get the folders and documents under this folder with the under_path function. Some folders represent a dossier / invoice folder and with this folder the primary key of the dossier / invoice is stored via meta data. While querying these folders by using sql we want to retrieve additional info which is stored in the relational tables: Customer info within a customer table, dossier info within a dossier table, invoice info with an invoice table, etc. Theoretically all available info must be retrieved, so this info preferably must not be stored as metadata (only the primary key and type to these rows and tables).
    My question: Is this the right way to go or are we going to face problems with this architecture? Is there a need to store all info as metadata or can it be done as I describe? So we want to link info from different tables to folders / documents in the repository. Because each folder can have metadata pointing to different tables we are facing (even with a small data set) performance issues. Can someone point me in the right direction?
    Thanks,
    Piotr Chabot Stadhouders
    Timeff
    The Netherlands

    Here's an example, tell me if this is what you need.
    Setup : the following creates a table to store a specific type of metadata, two folders, and finally creates a resource (JPEG image) and its associated metadata :
    SQL> create table character_metadata (
      2    character_id   number(6)
      3  , character_name varchar2(80)
      4  , origin         varchar2(80)
      5  , category       varchar2(30)
      6  );
    Table created.
    SQL> declare
      2    res boolean;
      3  begin
      4    res := dbms_xdb.CreateFolder('/ComicBooks');
      5    res := dbms_xdb.CreateFolder('/ComicBooks/Characters');
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> commit;
    Commit complete.
    SQL> declare
      2
      3    v_img_name     varchar2(260) := 'odie.jpg';
      4    v_metadata_id  character_metadata.character_id%type;
      5    res            boolean;
      6
      7  begin
      8
      9    /* Create the resource from the image file*/
    10    res := dbms_xdb.CreateResource('/ComicBooks/Characters/' || v_img_name, bfilename('TEST_DIR', v_img_name));
    11
    12    /* Create the metadata in the dedicated table */
    13    insert into character_metadata (character_id, character_name, origin, category)
    14    values(1, 'Odie', 'Garfield', 'Dog')
    15    returning character_id into v_metadata_id;
    16
    17    /* Add the pointer in the resource as user-defined metadata (non schema-based) */
    18    dbms_xdb.appendResourceMetadata(
    19      '/ComicBooks/Characters/' || v_img_name
    20    , xmltype( '<cm:CharacterMetadata xmlns:cm="http://mycompany.com/ComicBooks/Characters"><cm:id>' ||
    21               to_char(v_metadata_id) ||
    22               '</cm:id></cm:CharacterMetadata>' )
    23    );
    24
    25  end;
    26  /
    PL/SQL procedure successfully completed.
    SQL> commit;
    Commit complete.A possible query would look like :
    SQL> select cm.*
      2       , x.character_pic
      3  from resource_view v
      4     , xmltable(
      5         xmlnamespaces(
      6           'http://mycompany.com/ComicBooks/Characters' as "cm"
      7         , default 'http://xmlns.oracle.com/xdb/XDBResource.xsd'
      8         )
      9       , '/Resource'
    10         passing v.res
    11         columns metadata_id    number path 'cm:CharacterMetadata/cm:id'
    12               , character_pic  blob   path 'XMLLob'
    13       ) x
    14     , character_metadata cm
    15  where under_path(v.res, '/ComicBooks/Characters') = 1
    16  and cm.character_id = x.metadata_id
    17  ;
    CHARACTER_ID CHARACTER_NAME  ORIGIN          CATEGORY        CHARACTER_PIC
               1 Odie            Garfield        Dog             FFD8FFE000104A4649460001010000
                                                                 0100010000FFDB0084000906061412
                                                                 111414121416141514171717161718
                                                                 1815181D17171617151816151A1718
                                                                 1C261E1719231918141F2F2223272A
                                                                 2C2C2C161EThe image content is retrieved as a BLOB, along with its addtional data.

  • Column  format using SQL

    HI Thanks for the reply.
    IF I want to format the OPP_VALUE column How do I do format using sql
    Do I have to do it when I create the table? I loaded these data using spread sheet.
    I tried
    SELECT distinct tab.CUSTOMER, tab.SC, tab.HOURS,tab.OPP_VALUE, tab.opp_val_rank
    FROM
    (SELECT CUSTOMER, SC, HOURS, column OPP_VALUE format 999,999 OPP_VALUE, DENSE_RANK() OVER (order by OPP_VALUE DESC) opp_val_rank
    FROM FMW_ANALY) tab
    WHERE opp_val_rank<=10;
    I'm getting error ORA-00936: missing expression

    Hi I'm getting the following Result when I run the query
    SELECT distinct tab.CUSTOMER, tab.SC, tab.HOURS,tab.OPP_VALUE, tab.opp_val_rank
    FROM
    (SELECT CUSTOMER, SC, HOURS, to_char(OPP_VALUE,'999,999') OPP_VALUE, DENSE_RANK() OVER (order by OPP_VALUE DESC) opp_val_rank
    FROM FMW_ANALY) tab
    WHERE opp_val_rank<=10;
    CUSTOMER SC HOURS OPP_VALUE OPP_VAL_RANK
    Education and Training darryn 1 ######## 1
    Bank Limited matthew 40 ######## 3
    Bank Limited matthew 16 ######## 3
    Vicky

  • Can we use SQL developer tool to READ/WRITE BerkeleyDB by any means

    We use Berkeley Db as a persistent database, which holds data less frequently changed data. Can is it possible to use SQL Developer tool or any other front end tool that can connect and communicate to Berkeley db file for INSERT, UPDATE, DELETE records.

    I assume you're referring to Berkeley DB SQL (BDB SQL API).
    SQL Developer is not certified to work with BDB SQL; see the SQL Developer Certifications page.
    Something similar was asked some time ago, about connecting JDeveloper to BDB SQL; see this Re: How connect Oracle JDeveloper 11g to Berkeley DB 11g. The SQL tools in JDeveloper and SQL Developer are similar and built on the same components, so my answer there can be extended to SQL Developer as well. While you can probably have SQL Developer properly connect to a BDB SQL database, I am afraid you won't be able to do more than just viewing the data; likely any attempt to generate DDL or DML statements, export data, or run DML statements against the database will fail.
    If you migrated to BDB SQL from SQLite and were using a front-end tool for SQLite, it should be possible to use that with BDB SQL as well.
    Regards,
    Andrei

Maybe you are looking for

  • I am already paying for data so why is there a charge for tethering?

    I would really like to upgrade my Droid to a Droid 4 and use the WiFi hot spot feature. I have not done so yet because Verizon wants to charge me to use this feature of the phone. This appears to be illegal and I cannot understand and justify paying

  • Trying to log in but wont accept my date of birth how can i put this right

    i can't access my account  wont accept my date of birth how do i right this?

  • BorderManager - Where do we go from here ?

    Good Afternoon, I have recently been experiencing some problems with our BorderManager Server, which has kicked off some debate about what to do now that BM is reaching it's projected End Date for General Support. I would like to pose the question to

  • Install Analytic Workspace Manager

    Hi I have installed Oracle 10g(10.1.0.2) with OLAP option enabled. I would like to create some cubes using Analytic Workspace manager. When I look into Oracle HomeàIntegrated Management Tools, I wouldn't find Analytic Workspace manager. Do I need to

  • System Requirements for PeopleSoft 9.0

    Does anyone know where I can get system requirements (cpu, memory size, database capacity and other hardware related items) for setting up and installing PeopleSoft ELM 9.0 ? I can't seem to locate any information on the hardware specifications for t