Query need for Joins

ORD :
ORD_ID
ORD_DATE
CUST_ID
ORD_TOTAL
CUST :
CUST_ID
CUST_NAME
CITY
QUEST:
1. Irrespective of years write a query to find order which are placed between 15th and 31st of month september ?

31st of month september ?Don't know who made up those interview questions, but september only has 30 days....
SQL> select last_day(add_months(sysdate, -1)) from dual;
LAST_DAY(ADD_MONTHS
30-09-2010
1 row selected.You can find information regarding the last_day and add_months functions and other DATE datatype related stuff by doing a search in the Docs @
http://www.oracle.com/pls/db102/homepage
http://www.oracle.com/pls/db112/homepage

Similar Messages

  • Help Needed For joins

    Hi All,
    I am new to oracle.I have a requirement. i need to display sales fields for a particular time as below.
    Time    Sales
    6-7 3333
    7-8 45345
    8-9 546
    But the min time and max time are coming from different query and sales fields coming from different.Now i need to join both queries to get the results.But there is no common column.I tried with sub query there also i am getting error.Please find the queries and help me
    Hour Group Query:
    select
    time1.*,
    (select if (time_format(dt.curr_time, '%H') <
    time_format(ifnull((SELECT prop_value FROM cust_conv_properties c where prop_key = 'DayStartingTime'), '00:00:00'), '%H'),
    date_format(date_add(dt.curr_time, INTERVAL 0 DAY),'%d/%m/%Y'),
    date_format(dt.curr_time,'%d/%m/%Y')) as curr_date
    from
    (select concat(date_format(str_to_date('23/10/2011','%d/%m/%Y'),'%Y-%m-%d'), ' ', '00:00:00') as curr_time) dt) as report_date
    from
    (select
    -- 'S' temp,
    cast(min(cchg.from_hour) as unsigned) as min_value,
    cast(max(cchg.to_hour) as unsigned) as max_value,
    concat(concat(min(cchg.from_hour),''),'-',concat(max(cchg.to_hour),'')) as time_diff
    from
    cust_conv_hour_group as cchg
    where
    cchg.group_value in (SELECT distinct if(group_value = (SELECT min(group_value) FROM cust_conv_hour_group),
    (SELECT max(group_value) FROM cust_conv_hour_group), group_value-1) as group_value
    FROM cust_conv_hour_group c where from_hour <= cast(time_format('23:00:00','%H') as unsigned)
    and
    to_hour > cast(time_format('00:00:00','%H') as unsigned))
    group by
    cchg.group_value
    ) time1
    Sales Fields Query:
    SELECT
    if(count(cons.wr_tarSale)=0,0, cons.wr_tarSale) wr_tarSale,
    if(count(cons.wr_actSale)=0,0, cons.wr_actSale) wr_actSale,
    if(count(cons.wr_tarTrans)=0,0, cons.wr_tarTrans) wr_tarTrans,
    if(count(cons.wr_actTrans)=0,0, cons.wr_actTrans) wr_actTrans,
    if(count(cons.tarSale)=0,0, cons.tarSale) tarSale,
    if(count(cons.actSale)=0,0, cons.actSale) actSale,
    if(count(cons.varSale)=0,0, cons.varSale) varSale,
    if(count(cons.tarTrans)=0,0, cons.tarTrans) tarTrans,
    if(count(cons.actTrans)=0,0, cons.actTrans) actTrans,
    if(count(cons.actAds)=0,0, cons.actAds) actAds,
    if(count(cons.actUpt)=0,0, cons.actUpt) actUpt,
    if(count(cons.tarAds)=0,0, cons.tarAds) tarAds,
    if(count(cons.tarUpt)=0,0, cons.tarUpt) tarUpt,
    if(count(cons.actConv)=0,0, cons.actConv) actConv,
    if(count(cons.tarTplh)=0,0, cons.tarTplh) tarTplh,
    if(count(cons.actBlank1)=0,0, cons.actBlank1) actBlank1,
    if(count(cons.actBlank2)=0,0, cons.actBlank2) actBlank2,
    if(count(cons.actTplh)=0,0, cons.actTplh) actTplh,
    if(count(cons.sDTarSale)=0,0, cons.sDTarSale)sDTarSale,
    if(count(cons.sDTarTrans)=0,0, cons.sDTarTrans)sDTarTrans,
    if(count(cons.sDTarQty)=0,0, cons.sDTarQty)sDTarQty,
    if(count(cons.sDTarFF)=0,0, cons.sDTarFF)sDTarFF
    FROM
    SELECT
    ifnull(sum(ccsr.target_sale),0) wr_tarSale,
    ifnull(sum(ccsr.actual_sale),0) wr_actSale,
    ifnull(sum(ccsr.actual_transaction_count),0) wr_actTrans,
    ifnull(sum(ccsr.target_transaction_count),0) wr_tarTrans,
    round(ifnull(sum(ccsr.target_sale),0),2) tarSale,
    round(ifnull(sum(ccsr.actual_sale),0),2) actSale,
    round(round(ifnull(sum(ccsr.actual_sale),0),2)- round(ifnull(sum(ccsr.target_sale),0),2),2) varSale,
    round(ifnull(sum(ccsr.actual_transaction_count),0),0) actTrans,
    round(ifnull(sum(ccsr.target_transaction_count),0),0) tarTrans,
    0 actBlank1,
    round(ifnull((sum(ccsr.actual_sale)/sum(ccsr.actual_transaction_count)),0),2) actAds,
    round(ifnull((sum(ccsr.target_sale)/sum(ccsr.target_transaction_count)),0),2) tarAds,
    round(ifnull((sum(ccsr.actual_quantity)/sum(ccsr.actual_transaction_count)),0),2) actUpt,
    round(ifnull((sum(ccsr.target_quantity)/sum(ccsr.target_transaction_count)),0),2) tarUpt,
    round(ifnull((sum(ccsr.actual_transaction_count)/sum(ccsr.actual_footfalls))*100,0),2) actConv,
    0 actBlank2,
    0 actBlank3,
    round(ifnull((sum(ccsr.actual_footfalls)/sum(ccsr.actual_man_hours)),0),2) actTplh,
    round(ifnull((sum(ccsr.target_footfalls)/sum(ccsr.target_man_hours)),0),2) tarTplh,
    round(ifnull(ccsrs.target_sale,0),2) as sDTarSale,
    round(ifnull(ccsrs.target_transaction_count,0),0) as sDTarTrans,
    ifnull(ccsrs.target_quantity,0) as sDTarQty,
    ifnull(ccsrs.target_footfalls,0) as sDTarFF
    FROM
    cust_conv_store_report ccsr
    inner join cust_conv_store_report_summary ccsrs on(ccsrs.brand_code=ccsr.brand_code and ccsrs.category=ccsr.category and
                                  ccsrs.store_date=ccsr.store_date and ccsrs.value_type=ccsr.value_type)
    WHERE
    ccsr.value_type='B' and
    ccsr.brand_code= ? AND
    ccsr.store_date = date_format(str_to_date(?,'%d/%m/%Y'),'%Y-%m-%d')
    AND HOUR((TIME(ccsr.transaction_time))) >= (?) AND HOUR((TIME(ccsr.transaction_time)))< (?)
    GROUP BY
    ccsr.brand_code
    ) cons;
    Edited by: 992887 on Mar 10, 2013 4:25 AM

    992887 wrote:
    Hi All,
    I am new to oracle.code below is NOT valid Oracle syntax.
    post results from valid Oracle SQL below
    SELECT * FROM V$VERSION;
    I have a requirement. i need to display sales fields for a particular time as below.
    Time    Sales
    6-7 3333
    7-8 45345
    8-9 546
    But the min time and max time are coming from different query and sales fields coming from different.Now i need to join both queries to get the results.But there is no common column.I tried with sub query there also i am getting error.Please find the queries and help me
    Hour Group Query:
    select
    time1.*,
    (select if (time_format(dt.curr_time, '%H') <
    time_format(ifnull((SELECT prop_value FROM cust_conv_properties c where prop_key = 'DayStartingTime'), '00:00:00'), '%H'),
    date_format(date_add(dt.curr_time, INTERVAL 0 DAY),'%d/%m/%Y'),
    date_format(dt.curr_time,'%d/%m/%Y')) as curr_date
    from
    (select concat(date_format(str_to_date('23/10/2011','%d/%m/%Y'),'%Y-%m-%d'), ' ', '00:00:00') as curr_time) dt) as report_date
    from
    (select
    -- 'S' temp,
    cast(min(cchg.from_hour) as unsigned) as min_value,
    cast(max(cchg.to_hour) as unsigned) as max_value,
    concat(concat(min(cchg.from_hour),''),'-',concat(max(cchg.to_hour),'')) as time_diff
    from
    cust_conv_hour_group as cchg
    where
    cchg.group_value in (SELECT distinct if(group_value = (SELECT min(group_value) FROM cust_conv_hour_group),
    (SELECT max(group_value) FROM cust_conv_hour_group), group_value-1) as group_value
    FROM cust_conv_hour_group c where from_hour <= cast(time_format('23:00:00','%H') as unsigned)
    and
    to_hour > cast(time_format('00:00:00','%H') as unsigned))
    group by
    cchg.group_value
    ) time1
    Sales Fields Query:
    SELECT
    if(count(cons.wr_tarSale)=0,0, cons.wr_tarSale) wr_tarSale,
    if(count(cons.wr_actSale)=0,0, cons.wr_actSale) wr_actSale,
    if(count(cons.wr_tarTrans)=0,0, cons.wr_tarTrans) wr_tarTrans,
    if(count(cons.wr_actTrans)=0,0, cons.wr_actTrans) wr_actTrans,
    if(count(cons.tarSale)=0,0, cons.tarSale) tarSale,
    if(count(cons.actSale)=0,0, cons.actSale) actSale,
    if(count(cons.varSale)=0,0, cons.varSale) varSale,
    if(count(cons.tarTrans)=0,0, cons.tarTrans) tarTrans,
    if(count(cons.actTrans)=0,0, cons.actTrans) actTrans,
    if(count(cons.actAds)=0,0, cons.actAds) actAds,
    if(count(cons.actUpt)=0,0, cons.actUpt) actUpt,
    if(count(cons.tarAds)=0,0, cons.tarAds) tarAds,
    if(count(cons.tarUpt)=0,0, cons.tarUpt) tarUpt,
    if(count(cons.actConv)=0,0, cons.actConv) actConv,
    if(count(cons.tarTplh)=0,0, cons.tarTplh) tarTplh,
    if(count(cons.actBlank1)=0,0, cons.actBlank1) actBlank1,
    if(count(cons.actBlank2)=0,0, cons.actBlank2) actBlank2,
    if(count(cons.actTplh)=0,0, cons.actTplh) actTplh,
    if(count(cons.sDTarSale)=0,0, cons.sDTarSale)sDTarSale,
    if(count(cons.sDTarTrans)=0,0, cons.sDTarTrans)sDTarTrans,
    if(count(cons.sDTarQty)=0,0, cons.sDTarQty)sDTarQty,
    if(count(cons.sDTarFF)=0,0, cons.sDTarFF)sDTarFF
    FROM
    SELECT
    ifnull(sum(ccsr.target_sale),0) wr_tarSale,
    ifnull(sum(ccsr.actual_sale),0) wr_actSale,
    ifnull(sum(ccsr.actual_transaction_count),0) wr_actTrans,
    ifnull(sum(ccsr.target_transaction_count),0) wr_tarTrans,
    round(ifnull(sum(ccsr.target_sale),0),2) tarSale,
    round(ifnull(sum(ccsr.actual_sale),0),2) actSale,
    round(round(ifnull(sum(ccsr.actual_sale),0),2)- round(ifnull(sum(ccsr.target_sale),0),2),2) varSale,
    round(ifnull(sum(ccsr.actual_transaction_count),0),0) actTrans,
    round(ifnull(sum(ccsr.target_transaction_count),0),0) tarTrans,
    0 actBlank1,
    round(ifnull((sum(ccsr.actual_sale)/sum(ccsr.actual_transaction_count)),0),2) actAds,
    round(ifnull((sum(ccsr.target_sale)/sum(ccsr.target_transaction_count)),0),2) tarAds,
    round(ifnull((sum(ccsr.actual_quantity)/sum(ccsr.actual_transaction_count)),0),2) actUpt,
    round(ifnull((sum(ccsr.target_quantity)/sum(ccsr.target_transaction_count)),0),2) tarUpt,
    round(ifnull((sum(ccsr.actual_transaction_count)/sum(ccsr.actual_footfalls))*100,0),2) actConv,
    0 actBlank2,
    0 actBlank3,
    round(ifnull((sum(ccsr.actual_footfalls)/sum(ccsr.actual_man_hours)),0),2) actTplh,
    round(ifnull((sum(ccsr.target_footfalls)/sum(ccsr.target_man_hours)),0),2) tarTplh,
    round(ifnull(ccsrs.target_sale,0),2) as sDTarSale,
    round(ifnull(ccsrs.target_transaction_count,0),0) as sDTarTrans,
    ifnull(ccsrs.target_quantity,0) as sDTarQty,
    ifnull(ccsrs.target_footfalls,0) as sDTarFF
    FROM
    cust_conv_store_report ccsr
    inner join cust_conv_store_report_summary ccsrs on(ccsrs.brand_code=ccsr.brand_code and ccsrs.category=ccsr.category and
                                  ccsrs.store_date=ccsr.store_date and ccsrs.value_type=ccsr.value_type)
    WHERE
    ccsr.value_type='B' and
    ccsr.brand_code= ? AND
    ccsr.store_date = date_format(str_to_date(?,'%d/%m/%Y'),'%Y-%m-%d')
    AND HOUR((TIME(ccsr.transaction_time))) >= (?) AND HOUR((TIME(ccsr.transaction_time)))< (?)
    GROUP BY
    ccsr.brand_code
    ) cons;
    Edited by: 992887 on Mar 10, 2013 4:25 AM

  • SAP Query - Need to join 3 Tables via outer join

    Hi,
    I need to join 3 Tables using SAP Query. I wish an OUTER JOIN to be performed for the table join.
    For Example:
    Table 1 has 1000 Entries           Field A             Field B          
    Table 2 has 300 Entries             Field A            Field C
    Table 3 has 100 Entries             Field A           Field D
    The normal Join (INNER JOIN) gives me only the records that exists in all the 3 Tables.
    But what i need is:
    In the above example, If one entry in Table 1 has no matching records in Table 2 / Table 3, there should be an output entry in the SAP Query like
    Field A            Field B              Field C            Field  D
    xxxx              yyyy                  Blank             Blank
    If there is a common record that exists in the tables, that record should appear in the same entry in the Query output.
    Field A            Field B              Field C            Field  D
    xxxx              yyyy                  zzzz              aaaa
    In this way, there should be a minimum of 1000 entries (Largest no of records in the Tables joined). More than 1000 records in the Query output depends on the number of common records.
    Kindly help if you have come across such a scenario.
    thanks & regds
    sriram

    Hi
    Please join the outer join as below
    Table1 with Field A  to Table 2 Field A-----outer join
    Table1 with Field A  to Table 3 Field A------outer join
    then you get the out put as per your requirement
    Regards
    Damu

  • Explanation needed for Join rules

    I try to configure the join Engine for some days now, andf probably I got something completly wrong... Here is what I try:
    I have a "Participating View" (which is a NT Connector View) and a Meta View. When I enable the NT Connector View for the join engine, all entries flow from NT Connector View to the Meta View.
    But when I change something in Meta View, it does not flow to the Connector View. I don't understand why.
    Settings in Participant View are:
    Attribute flow:
    to connector atomic
    to meta view: atomic
    joinrules:
    to conn: atomic
    to mv: "testruleset"
    DN mapping rules:
    to conn: atomic
    to mv: atomic
    filters:
    to conn: none
    to mv: none
    entry default ownership:
    to conn: Meta View
    to mv: Connector View
    entry default membership:
    To connector: Not a member of CV
    to mv: Member of CV
    "testRuleset" has one join rule:
    1. Optional Token Assignments: <none>
    Selection Criteria: <none>
    givenname=%givenname%
    As I understood the documentation, this rule should join entries, which have the same givenname.
    So if I have two entries:
    in MV:
    dn: uid=test1,o=company
    givenname: jack
    sn: smith
    uid: test1
    telephonenumber: 123
    and in CV:
    dn: uid=test2,o=company
    givenname: jack
    sn: smith
    uid: test2
    mail: [email protected]
    This rule should (as I read the documentation) join both entries in the MV to one entry containing a mail address an a telephone number, but it does not.
    Could anyone correct tell me what part I got wrong or post a working example?
    Thanks!
    Florian

    Hi, if you've just one Connector View (CV) and you want to synchronise entries from the CV to the MetaView (MV) then you need a "DN Mapping Rule". It's the purpose of the DNMappingRule to create the new DistinguishedName and entry in the target view. You do not have a DNMappingRule setup typically the rule would be something like uid=%uid% assuming uid is the RDN.
    No not use Atomic where possible it's best practise to apply more control over the flow of attributes using an Attribute Flow Rule.
    You don't need a Join Rule if there's only one datasource (ConnectorView) , the Join Rule is used to join entries that are split across multiple Data Sources say perhaps in Oracle and Directory Server.
    Hope this helps,
    Paul

  • Query Needed for Partitioning table

    Hi,
    I have created a table called Test. There is a column named business_name.
    There are several businesses like ABC,BCD,ADE....
    There will be lakhs of rows corresponding to each business, i mean there will be lakhs of entires corresponding to ABC,BCD....
    So i like to partition the table according to business_name so that the search will be more faster.As we had partitioned according to the business_name, i hope we need to search only on the partition corresponding to the particular business.
    can any one provide the Query to partition the table ' TEST ' according to the column ' business_name ' .
    Also can anyone provide Query to modify the already existing table ' TEST ' to incorporate partition for the column ' business_name '.

    We can partiton a table by the following
    create table Generalledger (
         record_id     number,
         business_name     varchar2(3)
         sales_dt     date,
         amount     number(10)
    partition by list (business_name)
    partition ct values ('ABC'),
    partition ca values ('BCD'),
    partition def values (default)
    But if we dont know the values like 'ABC' , 'BCD'
    ....how can we do the partitionuse SQL to generate part (or all) of your DDL statement. The following will output one partition statement for each business_name:
    SELECT DISTINCT 'partition p_' || BUSINESS_NAME || ' values (''' ||
                     BUSINESS_NAME || '''),'
    FROM GENERALLEDGER;

  • Decode query need for aging

    Hi All,
    Following is the query which is working for aging for condition and round(st.close_dt - st.open_dt) >60 and corresponding column output count(round(st.close_dt - st.open_dt)) ">60" but we need the same in report of column of
    count(round(st.close_dt - st.open_dt)) "<15"
    count(round(st.close_dt - st.open_dt)) "16 to 30"
    count(round(st.close_dt - st.open_dt)) "31 to 45"
    count(round(st.close_dt - st.open_dt)) "45 to 60"
    which is based on condition round(st.close_dt - st.open_dt) <15
    round(st.close_dt - st.open_dt) between 16 and 31
    round(st.close_dt - st.open_dt) between 31 and 45
    round(st.close_dt - st.open_dt) between 46 and 60
    but we can't use this all condition at a time as individual it is working fine.
    Could you please let me know how we can user this all in one so the I can get the output at a time <15, 16 to 30, 31 to 45, 46 to 60 and >60.
    {select       count(round(st.close_dt - st.open_dt)) ">60"
      from stat.csr_master_tbl m,
         stat.customers c,
         stat.proj_csrs p,
         stat.appl_type ap,
        stat.csr_type_cd tp,
         stat.csr_status st,
         stat.csr_status_cd sc,
         stat.wrkflw_defn w
    where m.cust_id = c.cust_id
    and m.csr_id  = p.csr_id (+)
    and m.sd_cd  = p.sd_cd (+)
    and m.appl_cd = ap.appl_cd
    and m.sd_cd = ap.sd_cd
    and m.sd_cd = tp.sd_cd
    and m.csr_type = tp.csr_type_cd
    and m.sd_cd = st.sd_cd
    and m.csr_id = st.csr_id
    and st.csr_status_cd = sc.csr_status_cd
    and st.sd_cd = sc.sd_cd
    and tp.csr_type_cd = sc.csr_type_cd
    and m.wrkflw_id = w.wrkflw_id
    and (m.sd_cd in ('11i','AVA') or (m.sd_cd in ('STR') ))
    and (    st.close_dt between to_date(:beg_date,'MM/DD/YYYY') and to_date(:end_date,'MM/DD/YYYY')
           or st.closed_status_flag <> 'Y')
    --and sc.descr <> 'Cancel'
    AND sc.descr  IN ('Close')
    and p.proj_cd='OAPS'
    and round(st.close_dt - st.open_dt) >60
    and tp.descr in ('Break-Fix Datafix'
    ,'Break-Fix Configuration'
    ,'Break-Fix  Development'
    ,'Vendor Patch')
    and c.first_name in ('Springville'
    ,'Cookeville'
    ,'Bangalore'
    ,'Deer Park'
    ,'Sulphur Springs'
    ,'P11i'
    ,'Singapore'
    ,'Bangalore Chemical'
    ,'Baton Rouge'
    ,'Kaohsiung'
    ,'Bangalore Controls'
    ,'Damam'
    ,'Dayton Foundry'
    ,'Edmonton'
    ,'Jebel Ali'
    ,'Melbourne'
    ,'Philadelphia')}

    You might try something like
    select
       sum(case when round(st.close_dt - st.open_dt) < 15              then 1 else 0 end) "< 15",  -- shouldn't it be <=15?
       sum(case when round(st.close_dt - st.open_dt) between 16 and 30 then 1 else 0 end) "16 to 30",
       ...and you should have posted this question in the PL/SQL forum.
    Edited by: UW (Germany) on 17.08.2012 12:15

  • QUERY NEED FOR TIME DIFFERENCE

    Hi
    I need a query to find the difference between time
    for example
    5.00 hours - 0.30 minutes = 4.30 hours
    Thanks in Advance
    Adina

    Is this what you are looking for -
    1  select to_date('05:00', 'hh24:mi') - 0.5/24   --Subtract ½ Hr from time
      2* from dual
    SQL> /
    TO_DATE('05:
    200804010430
      1  select to_date('05:00', 'hh24:mi') - 3/24     --Subtract 3 Hrs from time
      2* from dual
    SQL> /
    TO_DATE('05:
    200804010200
      1  select to_date('05:30', 'hh24:mi') + 0.5/24   --Adds ½ Hr to the time
      2* from dual
    SQL> /
    TO_DATE('05:
    200804010600
      1  select to_date('20080416 00:02', 'yyyymmdd hh24:mi') - 0.5/24     --Subtract ½ Hr from time  2* from dual
    SQL> /
    TO_DATE('200
    200804152332Shailender Mehta

  • Query needed for Cumulative data

    HI Friends,
    I need output like this.
    Frequency     Percent (%) Cumulative
    Frequency     Cumulative Percent
    4468     0.91     4468     0.91
    21092     4.31     25560     5.23
    57818     11.82     83378     17.05
    6274     1.28     89652     18.33
    I am using Oracle 9i.
    My output data like this and I need to write the query for 3 columns (Percent ,Cumulative frequency and Cumulative percent)
    1:The formula for Percent column data is (Frequency/Sum of cumulative frequency)*100
    2:The formula for Cumulative Frequency column data is (Cumulative of Frequency column data)
    3:The formula for Cumulative Percent column data is (Cumulative of Percent column data)
    What should be the analytic function and how to write the query.
    Thanks,
    Lony

    Hi Friends,
    I need output like this.
    Frequency Percent (%) Cumulative Frequency Cumulative Percent
    4468 0.91 4468 0.91
    21092 4.31 25560 5.23
    57818 11.82 83378 17.05
    6274 1.28 89652 18.33
    I am using Oracle 9i.
    My output data like this and I need to write the query for 3 columns (Percent ,Cumulative frequency and Cumulative percent)
    1:The formula for Frequency column data is sum of (dd+cc+mc_cc_mc).
    1:The formula for Percent column data is (Frequency/Sum of cumulative frequency)*100
    2:The formula for Cumulative Frequency column data is (Cumulative of Frequency column data)
    3:The formula for Cumulative Percent column data is (Cumulative of Percent column data)
    What should be the analytic function and how to write the query.Please find the sample data and table script.
    CREATE TABLE all_lony (
    campno varchar2(20),
    dd INTEGER,
    cc INTEGER,
    mc INTEGER,
    cc_mc INTEGER
    insert into all_lony (campno,dd,cc,mc,cc_mc)
    values(36,156,1320,445,2547);
    insert into all_lony (campno,dd,cc,mc,cc_mc)
    values(40,233,19711,263,885);
    =============
    Please find my query below
    SELECT campno
    || ','
    || dm
    || ','
    || cc
    || ','
    || mc
    || ','
    || cc_mc
    || ','
    || frequency
    || ','
    || per
    ||','
    ||cumulative_fr
    ||','
    || SUM (per) OVER (ORDER BY per ROWS UNBOUNDED PRECEDING)
    FROM (SELECT q3.campno campno, q3.dm, q3.cc, q3.mc, q3.cc_mc,
    q3.frequency, q3.cumulative_fr,
    (q3.Frequency / SUM (q3.cumulative_fr)) * 100 per
    FROM (SELECT q2.campno campno, SUM (q2.dm) dm, SUM (q2.cc) cc,
    SUM (q2.mc) mc, SUM (q2.cc_mc) cc_mc,
    (SUM ( NVL (q2.dm, 0)
    + NVL (q2.cc, 0)
    + NVL (q2.mc, 0)
    + NVL (q2.cc_mc, 0)
    ) frequency,
    SUM (SUM ( NVL (q2.dm, 0)
    + NVL (q2.cc, 0)
    + NVL (q2.mc, 0)
    + NVL (q2.cc_mc, 0)
    ) OVER (ORDER BY SUM ( NVL (q2.dm, 0)
    + NVL (q2.cc, 0)
    + NVL (q2.mc, 0)
    + NVL (q2.cc_mc,0)
    ) ROWS UNBOUNDED PRECEDING)
    cumulative_fr
    from all_lony
    q1 )q2
    GROUP BY q3.campno) q3
    GROUP BY campno, dm, cc, mc,cc_mc, frequency,cumulative_fr)
    Can anybody just verify the query and let me know.

  • Query needed for the below requirement

    Hi,
    I have three tables structures like below.
    tableA - LINE_ID, VENDOR_ID,DEAL_SITE_ID
    tableB - LINE_ID, DEAL_SITE_ID
    tableC - DEAL_ID,VERSION, DEAL_SITE_ID
    Now the requirement is I have to fetch all distinct VENDOR_ID from tableA with some given DEAL_ID (100001) and VERSION (1), only Problem is in tableA the rows which have LINE_ID will not have DEAL_SITE_ID and vice versa. I've used the below query for this purpose but wanted to know if there is any better solution.
    select distinct VENDOR_ID from tableA where deal_site_id in
    (select deal_site_id from tableC where deal_id = 100001 and snapshot_ver = 1)
    UNION
    select distinct VENDOR_ID from tableA where line_id in
    (select line_id from tableB where deal_site_id in
    (select deal_site_id from tableC where deal_id = 100001 and snapshot_ver = 1))
    Regards,
    Subhadeep
    Edited by: sumajumd on Jul 17, 2012 2:33 AM

    Try regular joins (assuming column version should be snapshot_ver).
    Like this (untested):
    select tablea.vendor_id
    from   tablea
      inner join tablec on (tablea.deal_site_id = tablec.deal_site_id)
    where  tablec.deal_id      = 100001
    and    tablec.snapshot_ver = 1
    union
    select tablea.vendor_id
    from   tablea
      inner join tableb on (tableb.line_id      = tablea.line_id)
      inner join tablec on (tableb.deal_site_id = tablec.deal_site_id)
    where  tablec.deal_id      = 100001
    and    tablec.snapshot_ver = 1

  • Approval Query needed for AR Reserve Invoice

    Need to create an approval for delivery doc- If AR reserve invoice not paid need to triger an approval.  how can I cutomise the query to look at base document.
    SELECT DISTINCT  'TRUE' FROM OINV T0 WHERE T0.[isIns] = 'Y' AND  T0.[DocStatus] <> 'C'
    Thanks and Regards

    Hi Anoop,
    This one should do it I believe. I have attachde the query as not everything gets copied in this forum. The query below will not work.
    SELECT distinct 'true' FROM DLN1 T0 WHERE T0.[BaseType] = 13 and  $[$38.45.1] in (SELECT docentry  FROM OINV T0 WHERE isins = 'Y' and paidtodate <> doctotal)
    There are a few limitations with approvals in B1 that are based on values on the linelevel like this one.
    The query can not see past the first line of the document. So it will only check the basedoc of the first item in the Delivery (it is possible to add an item on the first line after copying the Reserve Invoice details into the delivery).
    Apart from that, the query only checks if the payment have been fully done "(paidtodate <> doctotal)", if it has been partially paid it will still trigger the approval. If partial payment is acceptable you can change that to "paidtodate <> 0".
    Hope it helps,
    Jesper

  • Sql query need for date format''Mon 23 Apr 16:45 pm'

    i need SQL query to print date like 'Mon 23 Apr 16:45 pm' format

    SQL> select to_char(sysdate,'Dy fmddfm Mon hh24:mi pm','nls_date_language=american') from dual
      2  /
    TO_CHAR(SYSDATE,'DY
    Fri 27 Apr 13:04 pm
    1 rij is geselecteerd.Regards,
    Rob.

  • Query need for transpose data output

    Dear All,
    I have a query regarding transpose output.
    for ex. I created one table employee in database
    create table emp(emp_no number,dept_id number(10));
    it is having data like....
    emp_no dept_id
    101 10
    102 20
    103 10
    104 10
    105 20
    so I want the output in transpose format like
    dept_id emp_no1 emp_no2 emp_no3
    10 101 103 104
    20 102 105
    can anybody suggest me any query for the above output.
    Thanks...
    Prashant....

    select dept_id
         , max (decode (emp_no, 101, emp_no))
         , max (decode (emp_no, 102, emp_no))
         , max (decode (emp_no, 103, emp_no))
         , max (decode (emp_no, 104, emp_no))
         , max (decode (emp_no, 105, emp_no))
      from test
    group by dept_idas in
    SQL> with test as
      2  (
      3  select 101 emp_no, 10 dept_id from dual union all
      4  select 102 emp_no, 20 dept_id from dual union all
      5  select 103 emp_no, 10 dept_id from dual union all
      6  select 104 emp_no, 10 dept_id from dual union all
      7  select 105 emp_no, 20 dept_id from dual
      8  )
      9  select dept_id
    10       , max (decode (emp_no, 101, emp_no)) emp1
    11       , max (decode (emp_no, 102, emp_no)) emp2
    12       , max (decode (emp_no, 103, emp_no)) emp3
    13       , max (decode (emp_no, 104, emp_no)) emp4
    14       , max (decode (emp_no, 105, emp_no)) emp5
    15    from test
    16   group by dept_id
    17  ;
       DEPT_ID       EMP1       EMP2       EMP3       EMP4       EMP5
            20                   102                              105
            10        101                   103        104

  • Query needed for projects??

    Hi ,
    Iam not aware of projects module,but i got a requirement to built a projects module related query in R12 module.
    My requirement is i need to built projects invoice query.All important columns like customer_name,project_number,
    agreement,task_no,task_types,quantity,uom,invoice_amount this is what they told.
    Please can any1 who have projects module knowledge,help me by building the query.
    Regards,
    Kranthi.

    Are you going to answer the question asked?... is it an Oracle Apps question? Then go to the Oracle Apps forum... the volunteers there have domain knowledge.. This is a "general" SQL and PL/SQL forum

  • Query needed for sorting by time value

    Hi Folks
    We have table it consists two columns like below
    Job_name varchar2(50)
    Scheduled_time date
    The filed scheduled time keep date and time value like below
    25-Jul-2009 4:00:10 AM
    26-Jul-2009 4:00:01 PM
    27-Jul-2009 4:00:00 PM
    28-Jul-2009 4:05:00 PM
    01-Jul-2009 4:06:00 PM
    02-Jun-2009 4:15:40 AM
    We need output as sorting by time value NOT date value. Expected output to be below
    25-Jul-2009 4:00:10 AM
    02-Jun-2009 4:15:40 AM
    27-Jul-2009 4:00:00 PM
    26-Jul-2009 4:00:01 PM
    28-Jul-2009 4:05:00 PM
    01-Jul-2009 4:06:00 PM
    I am using oracle 10G
    Thanks in Advance

    Here's how :
    SQL> create table job_table (job_name varchar2(50) not null, scheduled_time date);
    Table created.
    SQL> insert into job_table
      2  values ('Job_abc',to_date('25-JUL-2009 04:00:00','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> insert into job_table
      2  values ('Job_fdw',to_date('02-JUN-2009 04:15:40','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> insert into job_table
      2  values ('Job_fxj',to_date('27-JUL-2009 03:59:00','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> insert into job_table
      2  values ('Job_rjt',to_date('20-JUL-2009 14:59:00','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> alter session set nls_date_format='DD-MON-YYYY HH:MI:SS AM';
    Session altered.
    SQL> select job_name, scheduled_time from job_table
      2  order by to_char(scheduled_time,'HH24:MI:SS');
    JOB_NAME                                           SCHEDULED_TIME
    Job_fxj                                            27-JUL-2009 03:59:00 AM
    Job_abc                                            25-JUL-2009 04:00:00 AM
    Job_fdw                                            02-JUN-2009 04:15:40 AM
    Job_rjt                                            20-JUL-2009 02:59:00 PM
    SQL>

  • Query need for following question

    ORD :
    ORD_ID
    ORD_DATE
    CUST_ID
    ORD_TOTAL
    CUST :
    CUST_ID
    CUST_NAME
    CITY
    Quest:
    ORD_ID either less than 10 or greate than 50 also ORD_TOTAL >5000 ?

    What have you tried yourself sofar?
    And again:
    Quit polluting this forum, please.
    You're not providing any details reqarding your requirement, database version and so on...
    Read: http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    And use CREATE TABLE + INSERT INTO statements, formatted by using the {noformat}{noformat}tag when you want to post an example.
    For example, if you post:
    {noformat} select *
    from emp;
    {noformat}
    it will appear as: select *
    from emp;
    on this forum.
    Tags are explained in the FAQ, so read that too: http://forums.oracle.com/forums/help.jspa                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for