Query to find data of each month

Hello

I have 2 tables.

(1) Order_tb

Name Null? Type
----------------------------------------- -------- ----------------------------

ORDERID NOT NULL NUMBER
NUMBER OF CUSTOMERID
ORDERDATE DATE

(2) Order_d

Name Null? Type
----------------------------------------- -------- ----------------------------

ORDERID NUMBER
PRODUCTID NOT NULL NUMBER
PRODUCTNAME VARCHAR2 (20)
NUMBER OF SELLINGPRICE

I need to find the total find the selling price for each month of the year 2012 (orderdate) total.

I tried to use join, but I couldn't take the 2012 in particular data. Please help me on this issue.

Thank you

Published by: RSD on February 28, 2013 09:18

Hello

RSD wrote:
I tried to use join, but I couldn't take the 2012 in particular data. Please help me on this issue.

The WHERE clause below, is what limits the results for 2012.

SELECT       TRUNC (t.orderdate, 'MONTH')     AS month
,       SUM (d.sellingprice)          AS total_sellingprice
FROM       order_tb  t
JOIN       order_d   d  ON  d.orderid  = t.orderid
WHERE       t.orderdate  >= DATE '2012-01-01'
AND       t.orderdate  <  DATE '2013-01-01'
GROUP BY  TRUNC (t.orderdate, 'MONTH')
ORDER BY  TRUNC (t.orderdate, 'MONTH')
;

I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Simplify the problem. For example, pretend you're only interested in the first 3 or 4 months of 2012; We will find a solution tht can easily be adapted for 12 (or any other number) of motnhs.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}

Tags: Database

Similar Questions

  • Query to find data conneting that intersect each other.

    Hello

    I have a table like road_point_ids (script is below). Basically, this table have road_id with its start and its end point.

    I'm looking for a query that actually will connect each ID path beginning or end points.

    create the table road_point_ids

    (

    road_id number (10),

    start_point number (10),

    Number of end_point (10)

    );

    insert into road_point_ids

    values (1001, 10, 20);

    insert into road_point_ids

    values (1002, 20, 30);

    insert into road_point_ids

    values (1003, 30, 40);

    insert into road_point_ids

    values (1004, 40, 50);

    insert into road_point_ids

    values (1005, 50, 10);

    insert into road_point_ids

    values (1006, 70, 75);

    insert into road_point_ids

    values (1007, 30, 50);

    insert into road_point_ids

    values (1008, 10, 40);

    insert into road_point_ids

    values (1009, 80, 70);

    insert into road_point_ids

    values (1010, 90, 95);

    insert into road_point_ids

    values (1011, 50, 60);


    commit;

    SQL > select * from road_point_ids by 2;

    ROAD_ID START_POINT END_POINT

    -----------           -----------           -----------

    1001               10                    20

    1008               10                    40

    1002               20                    30

    1007               30                    50

    1003               30                    40

    1004               40                    50

    1011               50                    60

    1005               50                    10

    1006               70                    75

    1009               80                    70

    1010               90                    95

    11 selected lines

    In the example above only seven road_ids intersect at TWO points corresponding to start or end point.

    Output desired must be as...

    ROAD_IDSTART_POINTEND_POINT
    10011020
    10022030
    10033040
    10044050
    10055010
    10073050
    10081040

    7 selected lines

    I tried to use a lot of operator AND with the OR operator but sent to an incorrect result. Could someone provide me please help.

    Thanks in advance

    Saaz

    Hi, Saaz,

    How is this problem differs from your original problem?

    If it's just that the data is now contained in 2 tables (a few lines in a table, a few lines in the other) instead of a table, you can change my original solution by using a UNION to combine the two tables into one:

    WITH road_point_ids AS

    (

    SELECT road_id, start_point, end_point OF road_point_ids_1 UNION ALL

    SELECT road_id, start_point, end_point FROM road_point_ids_2

    )

    SELECT DISTINCT road_id, start_point, end_point

    OF road_point_ids

    WHERE CONNECT_BY_ISCYCLE = 1

    CONNECT BY NOCYCLE start_point = PRIOR end_point

    ;

    The WITH clause is new; the main request is that I posted earlier.

  • Get the date of each month in the last year

    Hi all

    I need to find the last date of the month for the year.

    Example:

    I used to spend the date or such year 2012 or 01-01-2012(DD-MM-YYYY)

    SQL query should return the last date of the month as

    31/01/2012

    28/02/2012

    31/03/2012

    30/04/2012

    .

    .

    .

    .

    .

    12/31/2012

    For more top the requirement that I wrote the SQL code following

    select rownum as row_count,
    case when rownum=1 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as Jan_month,
    case when rownum=2 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as Feb_month,
    case when rownum=3 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as mar_month,
    case when rownum=4 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as apr_month,
    case when rownum=5 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as may_month,
    case when rownum=6 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as jun_month,
    case when rownum=7 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as jul_month,
    case when rownum=8 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as aug_month,
    case when rownum=9 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as sep_month,
    case when rownum=10 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as oct_month,
    case when rownum=11 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as nov_month,
    case when rownum=12 then last_day(to_date(add_months(trunc(to_date('01-01-2012','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as dec_month
    
    
    from dual connect by level <= 12 order by rownum;
    
    
    
    
    

    Result

    Jan_MonthFeb_MonthMar_MonthApr_Monthmay_monthjun_monthjul_monthaug_monthsep_monthoct_monthnov_monthdec_month
    131/01/2014
    228/02/2014
    331/03/2014
    430/04/2014
    531/05/2014
    630/06/2014
    731/07/2014
    831/08/2014
    930/09/2014
    1031/10/2014
    1130/11/2014
    1212/31/2012

    Except the result:

    am result except as single line such as

    Jan_MonthFeb_MonthMar_MonthApr_Monthmay_monthjun_monthjul_monthaug_monthsep_monthoct_monthnov_monthdec_month
    31/01/201228/02/201231/03/201230/04/201231/05/201230/06/201231/07/201231/08/201230/09/201210/31/201230/11/201212/31/2012

    Kindly give me suggestion to archive more high result.

    Thanks and greetings

    Saami

    I agree with Marcus Pivot is the way to go on this subject... But on the other hand you almost solved yourself... it was just a max function for your results:

    ---------

    select
    max(case  when rownum=1 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as Jan_month,
    max(case  when rownum=2 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as Feb_month,
    max(case  when rownum=3 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as mar_month,
    max(case  when rownum=4 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as apr_month,
    max(case  when rownum=5 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as may_month,
    max(case  when rownum=6 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as jun_month,
    max(case  when rownum=7 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as jul_month,
    max(case  when rownum=8 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as aug_month,
    max(case  when rownum=9 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as sep_month,
    max(case  when rownum=10 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as oct_month,
    max(case  when rownum=11 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as nov_month,
    max(case  when rownum=12 then last_day(to_date(add_months(trunc(to_date('01-01-2012','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end) as dec_month
    from dual connect by level <= 12 order by rownum;
    

    AND to avoid hard-coding, you can also modify your query in the form:

    select
    max(case  when rownum=1 then last_day(to_date(to_char(rownum),'MM')) end) as Jan_month,
    max(case  when rownum=2 then last_day(to_date(to_char(rownum),'MM')) end) as Feb_month,
    max(case  when rownum=3 then last_day(to_date(to_char(rownum),'MM')) end) as mar_month,
    max(case  when rownum=4 then last_day(to_date(to_char(rownum),'MM')) end) as apr_month,
    max(case  when rownum=5 then last_day(to_date(to_char(rownum),'MM')) end) as may_month,
    max(case  when rownum=6 then last_day(to_date(to_char(rownum),'MM')) end) as jun_month,
    max(case  when rownum=7 then last_day(to_date(to_char(rownum),'MM')) end) as jul_month,
    max(case  when rownum=8 then last_day(to_date(to_char(rownum),'MM')) end) as aug_month,
    max(case  when rownum=9 then last_day(to_date(to_char(rownum),'MM')) end) as sep_month,
    max(case  when rownum=10 then last_day(to_date(to_char(rownum),'MM')) end) as oct_month,
    max(case  when rownum=11 then last_day(to_date(to_char(rownum),'MM')) end) as nov_month,
    max(case  when rownum=12 then last_day(to_date(to_char(rownum),'MM')) end) as dec_month
    from dual connect by level <= 12 order by rownum;
    

    Easy way: (without login)

    SELECT LAST_DAY (TO_DATE (ROWNUM, 'MM')) AS Jan_month,
           LAST_DAY (TO_DATE (ROWNUM + 1, 'MM')) AS Feb_month,
           LAST_DAY (TO_DATE (ROWNUM + 2, 'MM')) AS Mar_month,
           LAST_DAY (TO_DATE (ROWNUM + 3, 'MM')) AS Apr_month,
           LAST_DAY (TO_DATE (ROWNUM + 4, 'MM')) AS May_month,
           LAST_DAY (TO_DATE (ROWNUM + 5, 'MM')) AS Jun_month,
           LAST_DAY (TO_DATE (ROWNUM + 6, 'MM')) AS Jul_month,
           LAST_DAY (TO_DATE (ROWNUM + 7, 'MM')) AS Aug_month,
           LAST_DAY (TO_DATE (ROWNUM + 8, 'MM')) AS Sep_month,
           LAST_DAY (TO_DATE (ROWNUM + 9, 'MM')) AS Oct_month,
           LAST_DAY (TO_DATE (ROWNUM + 10, 'MM')) AS Nov_month,
           LAST_DAY (TO_DATE (ROWNUM + 11, 'MM')) AS Dec_month
      FROM DUAL
    

    See you soon,.

    Manik.

  • Calendar: How make you an appointment to repeat the same day (no date) of each month

    Hello

    I use the calendar in Windows RT.

    How to make an appointment to repeat, for example, the second Tuesday of each month?

    Hi Matt,

    Thanks for posting the question on Microsoft Community.

    According to the description, it looks like you want to make an appointment in a calendar application.

    I have these steps that should help you to solve the problem.

    Try these steps and check:

    a. open the Calendar application.

    b. Select the date to which you want to schedule the appointment.

    c. type view more.

    d. press the dropdown under what frequency and select on a monthly basis.

    e. tap save change which is at the top right of the screen.

    I hope this helps. If you have questions more related to Windows, feel free to post here at Microsoft Community.

  • Effective data growth each month/year

    Hi all
    Can any 1 give me the request, namely, the growth of the real (in MB) database of each month.

    And also the request, namely the growth of real data (in MB) each year.

    Thanks in advance

    Salvation;

    Please see:
    Script to list the details of the growth of the database per month [ID 135294.1]

    Respect of
    HELIOS

  • Problem with query to find data offset

    Hello PL/SQL gurus and Experts.

    I am not able to extract the data with the following table structure-
    drop table T2;
    create table T2(Stream, Trade, Fees) as select
    'MECHNICAL', 'Primary', '5534500' from dual union all select
    'ELECTRICAL', 'Secondary', '5285500' from DUAL union all select
    'MECHNICAL', 'Secondary', '2364535' from dual union all select
    'ELECTRICAL', 'Primary', '1734540' from DUAL union all select
    'MBE', 'Secondary', '3424500' from dual union all select
    'ELECTRONICS', 'Primary', '5004567' from DUAL union all select
    'ELECTRONICS', 'Secondary', '4543200' from DUAL union all select
    'COMPUTERS', 'Secondary', '5534500' from DUAL union all select
    'CIVIL', 'Primary', '2345500' from DUAL union all select
    'CIVIL', 'Secondary', '4456500' from DUAL union all select
    'COMPUTERS', 'Primary', '9542500' from DUAL;
    I want to extract the data in the following format-
    Stream          Trade          Fees
    MECHNICAL     Primary          5534500
              Secondary          2364535
    ELECTRICAL     Primary          1734540
              Secondary       5285500
    ELECTRONICS     Primary          5004567
              Secondary        4543200
    CIVIL          Primary          2345500
              Secondary         4456500
    MBE          Primary     
              Secondary       3424500
    Total                    34693342
    Now if I use the following query-
    SELECT CASE WHEN LAG(Stream||Trade) OVER (ORDER BY Stream, Trade, Fees) = Stream||Trade THEN NULL ELSE Stream END Stream
         , CASE WHEN LAG(Stream||Trade) OVER (ORDER BY Stream, Trade, Fees) = Stream||Trade THEN NULL ELSE Trade END Trade
         , CASE WHEN LAG(Fees) OVER (partition by Stream||Trade ORDER BY Stream, Trade, Fees) = Fees THEN NULL ELSE Fees END Fees
    FROM (     select distinct Stream, Trade, Fees from T2 ORDER BY Stream, Trade, Fees);
    SELECT  NVL2(LAG(Trade) OVER (PARTITION BY Stream, Trade ORDER BY Stream, Trade, Fees),Null,Trade) Trade,
         NVL2(LAG(Stream) OVER (PARTITION BY Stream, Trade ORDER BY Stream, Trade, Fees),Null,Stream) Stream,
         Fees
    from (select distinct Stream, Trade, Fees from T2)
    Kindly help me...
    Thank you all for your time and effort in advance.

    use the below. There would be better ways to achieve, I find it easier.

    with filtered as
    (
      select case row_number() over(partition by stream order by trade)
              when 1 then stream
              else null end stream2,trade,fees
      from t2
      order by stream,trade
    )
    select stream2 stream, trade, to_number(fees)
      from filtered
    union all
    select 'Total', null, sum(fees)
      from t2;
    
    STREAM      TRADE     TO_NUMBER(FEES)
    ----------- --------- ----------------------
    CIVIL       Primary   2345500
                Secondary 4456500
    COMPUTERS   Primary   9542500
                Secondary 5534500
    ELECTRICAL  Primary   1734540
                Secondary 5285500
    ELECTRONICS Primary   5004567
                Secondary 4543200
    MBE         Secondary 3424500
    MECHNICAL   Primary   5534500
                Secondary 2364535
    Total                 49770342     
    

    I hope that it meets your needs. If this isn't the case, then please don't forget to provide the expected results, because we have to guess, if you still want to exit expected Original or there is a diversion in it.

  • need help with query can find data back please help.

    Hi guys I have a table such as
    CREATE TABLE "FGL"
      (
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )
    and I have a data as such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');
    I need bascially to get the total of the budget column. However this is not as simple as it sounds good (at least not for the me.) totals carried forward to the new period. you will notice that you have a period column. Basically, what im is that
    fgl_grant_year 10 1 period = account 7600 its $100 and $100 for the period 2, you see $ 100 more, it wants to not be added to this is the door on the balance. that is $100.
    So im trying to write a query that basically does the following.
    IM considering a period for the sake of this example let period 1 I get anything else. I find that the greates contributes dumpster year the amount for the period 14 (which corresponds to the total of the previous year) and add it to the amount of the current year. in this case period 1 grnt_year 11
    the expected result is therefore $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400
    do not forget that I am not given a just a period of the year.
    any help you guys can give would be immensely appreciated. I tried to get this to work for more than 3 days now.
    Finally broke down and put together this post

    Published by: mlov83 on Sep 14, 2011 20:48

    Hello

    Thanks for posting the CREATE TABLE and INSERT statemnts; It is very useful.

    I'm not sure that understand your needs.
    The correct output will be just one line:

    TOTAL_BUDGET
    ------------
             700
    

    or will it be 3 ranks that you posted? I guess you want just line after line.

    Do you mean that you are given a period (for example, 1).
    First you have to find the largest gfl_grnt_year which is related to this period (in this case, 11).
    Then you need to add fgl_budget lines that have to be
    (1) the specific period and the largest fgl_grnt_year, or
    (2) perriod = 14 and the previous fgl_grnt_year (in this case, 10).
    Is this fair?

    If so, here's a way to do it:

    WITH     got_greatest_year     AS
    (
         SELECT     fgl.*     -- or whatever columns are needed
         ,     MAX ( CASE
                     WHEN  fgl_period = :given_period
                     THEN  fgl_grnt_year
                    END
                  ) OVER ()     AS greatest_year
         FROM     fgl
    )
    SELECT     SUM (fgl_budget)     AS total_budget     -- or SELECT *
    FROM     got_greatest_year
    WHERE     (     fgl_grnt_year     = greatest_year
         AND     fgl_period     = :given_period
         )
    OR     (     fgl_grnt_year     = greatest_year - 1
         AND     fgl_period     = 14
         )
    ;
    

    If you want the 3 lines you have posted, then change the main SELECT clause to ' SELECT * ' (or, instead of *, youcan the columns you want to see the list).

  • Query to find data on holidays

    Hi, I have a table for special leave, which looks like this:

    PROFILE_DAY VAR_DATE
    REGULAR_HOLIDAY01/01/2013
    H_WEEK_THURSDAY28/03/2013
    H_WEEK_FRIDAY29/03/2013
    REGULAR_HOLIDAY24/12/2013
    REGULAR_HOLIDAY25/12/2013
    REGULAR_HOLIDAY31/12/2013

    And another table (LOAD_PROFILE_TEST) that contains the values of (TIME_EQ) 0-24 LOAD_PROF1 intervals 0.25 for (PROFILE_DAY) MONDAY to SUNDAY including REGULAR_HOLIDAY, H_WEEK_THURSDAY and H_WEEK_FRIDAY.  Overall, this table contains 970 records (97 separate 0-24 with interval of 0.25 per PROFILE_DAY, with 10 PROFILE_DAY).

    TIME_EQ PROFILE_DAY LOAD_PROF1 LOAD_PROF2
    0REGULAR_HOLIDAY11.47
    0.25REGULAR_HOLIDAY11.27
    0.5REGULAR_HOLIDAY11.3
    0.75REGULAR_HOLIDAY11.08
    0MONDAY11.27
    0.25MONDAY11.33
    0.5MONDAY11.18

    Now I have this request to update the value of LOAD_PROF2 in the table every time that the V_DATE_OUT and V_DATE_IN parameters is entered:

    UPDATE LOAD_PROFILE_TEST

    SET LOAD_PROF2 = LOAD_PROF1 +: LOAD_DIFF

    WHERE UPPER (PROFILE_DAY) IN (select UPPER (to_char (: V_DATE_OUT + (level 1), "fmDAY")))

    of the double

    connect by level < =: V_DATE_IN -: + 1 V_DATE_OUT

    );

    where: LOAD_DIFF is some predetermined value.

    This query works fine if I'm trying to update regular days from MONDAY to SUNDAY.  What I would do is to determine if the two dates of setting, V_DATE_OUT & V_DATE_IN would fall under none of the holidays on the first table LOAD_PROFILE_TEST, and then update the lines only.  For example, V_DATE_OUT = 12/02/2013, Monday and V_DATE_IN = 06/12/2013, Friday.  The query above would update the values of the LOAD_PROF2 for PROFILE_DAY - MONDAY to FRIDAY, corresponding to the dates of 02/12/2013 and on 06/12/2013.  If, however, V_DATE_OUT = 23/12/2013, Monday and V_DATE_IN = 27/12/2013, Friday, it should update the lines corresponding to PROFILE_DAY - MONDAY 23/12/2013, THURSDAY for 26/12/2013, FRIDAY for 12 27, 2013, and REGULAR_HOLIDAY for the dates of 12 24, 2013 and 25/12/2013 since these two appear in the first table (table of holidays).  This scenario works the same way when V_DATE_OUT and/or V_DATE_IN enter the dates of 28/03/2013 and 29/03/2013.  All other dates not included in the table for special leave will be treated according to the day they fall on (from Monday to Sunday).  I hope my point is clear.  Thank you in advance.

    arms777 wrote:

    I have already given a test for the table,

    Frank pleased to display:

    "examples of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from this data."

    I do not see the second statement in the create table and insert statements. Do you expect to write us your data ourselfs?

    However I'll try it from scratch

    merge into LOAD_PROFILE_TEST t

    a_l'_aide_de)
    Select distinct
    Decode (var_date, null, theday, profile_day) profile_day
    BeO
    Select
    SUPERIOR (to_char (: V_DATE_OUT + (level 1), 'fmDAY')) theday
    ,: V_DATE_OUT + subsist (level 1)
    of the double
    connect by level<= :v_date_in="" -="" :v_date_out ="" +="">
    )
    REG_HOLIDAYS
    where
    subsist = var_date (+)

    ) g
    on (UPPER (t.PROFILE_DAY) = g.profile_day
    )
    When matched then update
    SET LOAD_PROF2 = LOAD_PROF1 +: LOAD_DIFF

    Post edited by: chris227
    Fixed: added update

  • date min for each month of list

    Hi all

    I need to select only minimal date for each month in this example query:
    select date '2011-01-04' as adate from dual union all 
    select date '2011-01-05' as adate from dual union all 
    select date '2011-01-06' as adate from dual union all 
    select date '2011-02-01' as adate from dual union all 
    select date '2011-02-02' as adate from dual union all 
    select date '2011-02-03' as adate from dual union all 
    select date '2011-10-03' as adate from dual union all 
    select date '2011-10-04' as adate from dual union all 
    select date '2011-10-05' as adate from dual 
    If the result should be:
    04.01.2011
    01.02.2011
    03.10.2011
    How can I make it?
    WITH dates
         AS (SELECT DATE '2011-01-04' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-01-05' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-01-06' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-02-01' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-02-02' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-02-03' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-10-03' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-10-04' AS adate FROM DUAL
             UNION ALL
             SELECT DATE '2011-10-05' AS adate FROM DUAL)
    SELECT TO_CHAR (MIN (adate), 'DD.MM.YYYY') adate
      FROM dates
      GROUP BY to_char(adate, 'YYYY.MM')
    
    ADATE
    --------------------
    03.10.2011
    01.02.2011
    04.01.2011
    
  • Query or logic to find several days through each month.

    Dear friends,

    I need your help to solve this problem.

    We have a now where we have to pay compensation to the employees based on their number of working days.

    Say, for example, if an employee has worked since March 3, 2012-April 5, 2012.

    We have a fixed value for a month 300 dirhams. But the number of days on s March 31 and number of days in the month of April are 30.

    So by compensation daily for March day would be 300/31 and April would be 300/30.

    We are looking for a logical opr query that calcluates first right number of days in each month (per month) and then calculate as below

    Number of working days in the month of March is 31-3 + 1 = 29

    Compensation of A1 = (300 * 29) / 31

    Number of working days in the month of April is 5 (must also find logical I guess)
    Allowance for A2 = (300 * 5) / 30

    Then A1 + A2.

    (E) would be the total quota when the number of months in all.

    Please guys any help would be greatly appricated.

    R

    Just a follow-up ;-)

    Note that you can almost get what you want with standard MONTHS_BETWEEN function [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions102.htm#i78039].
    But notice this quote from the documentation:

    >
    If date1 and date2 are the same days of the month or the last two days of the month, the result is always an integer. Otherwise the Oracle database calculates the fractional part of the result based on a month of 31 days and consider the time difference components date1 and date2.
    >

    It will always use one even if 31 days a month has fewer days.

    Then you could also implement the logic of my previous answer as your own function months_between implementation:

    create or replace function my_months_between (
       p_todate    date
     , p_fromdate  date
    )
       return number
    is
    begin
       return ((extract(day from last_day(p_fromdate))-extract(day from p_fromdate)+1) / extract(day from last_day(p_fromdate)))
            + (months_between(trunc(p_todate-1,'MM'),trunc(p_fromdate,'MM'))-1)
            + (extract(day from p_todate-1) / extract(day from last_day(p_todate-1)));
    end my_months_between;
    /
    

    I changed it to make it "compatible" with the standard function that it calculates up to but not including the parameter to date (which is correct when you are considering dates with time included, but I guess in your case, you have just date values.)

    Then, you can compare the results of the standard months_between with the new my_months_between:
    (Note that I have call the functions with the d2 + 1 to give the desired result of inclusion and to this day in the calculation).

    SQL> with testdata as (
      2     select date '2012-03-03' as d1, date '2012-04-05' as d2 from dual union all
      3     select date '2012-02-03' as d1, date '2012-05-02' as d2 from dual union all
      4     select date '2012-03-03' as d1, date '2012-03-10' as d2 from dual union all
      5     select date '2012-03-01' as d1, date '2012-07-31' as d2 from dual union all
      6     select date '2012-02-01' as d1, date '2012-03-01' as d2 from dual union all
      7     select date '2012-01-01' as d1, date '2012-03-25' as d2 from dual
      8  )
      9  --
     10  -- end of test data --
     11  --
     12  select months_between(d2+1, d1) std_months
     13       , 300 * months_between(d2+1, d1) std_allowance
     14       , my_months_between(d2+1, d1) my_months
     15       , 300 * my_months_between(d2+1, d1) my_allowance
     16    from testdata
     17  /
    
    STD_MONTHS STD_ALLOWANCE  MY_MONTHS MY_ALLOWANCE
    ---------- ------------- ---------- ------------
    1.09677419    329.032258 1.10215054   330.645161
             3           900 2.99555061   898.665184
    .258064516    77.4193548 .258064516   77.4193548
             5          1500          5         1500
    1.03225806    309.677419 1.03225806   309.677419
    2.80645161    841.935484 2.80645161   841.935484
    
    6 rows selected.
    

    For a large part of the data, both give the same result, especially when the two dates are in month of 31 days.
    To work from ' 2012-03-03' to '' 2012-04-05 standard service gives too little because it uses always 31 days, while my_months_between uses 30 days of April.

    "But note working from '' 2012-02-03 to 2012 - 05 - 02. He jumped 2 days in February and has worked 2 days in May - the standard function concludes he works precisely 3 months.
    But my_months_between computes fraction 27/29 months in February, then March and April like 2 months, and then the fraction 2/31 months in May - which gives a total of 2.99555061 instead of 3 months.

    Just something to be aware of ;-)

  • Need to query to find missing months between two dates.

    A bank customer a monthly overview of databases (in the tens of millions of accounts)

    The data are sent with a line per account each month.  It is stored in a table called "ACCOUNTS_TAB".

    Fields on registration, which

    Column

    Description

    Example of format.

    * YRMTH-1

    Year and month of the snapshot

    6-character numeric, 4-digit year added to months of 2 digits, example 201301, 201311

    * AccountID

    Unique identifier for an account.

    Integer, example 100098322

    Opening balance - 1

    Initial account balance at the closing of the previous month

    $30000

    Closing balance - 1

    The account balance at the end of the month of closing

    $34200

    Class-1 relative to investments

    .....

    ...

    .....

    ......

    .....

    Many more columns, two favorites (*) columns are alone, that you will need for the query. There are no columns to tell when an account is closed, or has just opened, and not separate "master account" - you use this single table for your query that results.

    The table was in place from 200301, so many accounts have dozens of lines, if they have been open for many years and other only 1 or 2 ranks, if new.

    Write a query to give just a list of accountDs that meet the following criteria.

    1. 1) has a record for specific 201503
    2. 2) was also a record for the month specific 201602
    3. 3) missing one or several months between these two records.

    A good account which was opened from 201503 to 201602 inclusive would of course have lines for

    201503

    201504

    201505

    201506

    201507

    201508

    201509

    201510

    201511

    201512

    201601

    201602

    It's good to hardcode the month of departure (201503), end of month (201602) and the actual number of months between them (10 exclusive or 12 inclusive) as part of your query.

    Once again the account must meet all 3 criteria to be an account issue.  If only, they have a partial set of these documents but do not have the month of departure, or is not the end of the month, it is not a problem, only when they have so specified and end early and not a full between game.


    Help, please!

    Maybe this...

    -----

    -The Dataset for the test begins

    WITH dataset (ACCOUNT_NO, DATES)

    AS (SELECT 100, DOUBLE 201503

    UNION ALL

    SELECT 100, DOUBLE 201504

    UNION ALL

    SELECT 100, DOUBLE 201505

    UNION ALL

    SELECT 100, DOUBLE 201506

    UNION ALL

    SELECT 100, DOUBLE 201507

    UNION ALL

    SELECT 100, DOUBLE 201508

    UNION ALL

    SELECT 100, 201509 OF THE DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201510

    UNION ALL

    SELECT 100, 201511 OF THE DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201512

    UNION ALL

    SELECT 100, 201601 DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201602

    UNION ALL

    SELECT 200, DOUBLE 201503

    UNION ALL

    SELECT 200, DOUBLE 201504

    UNION ALL

    SELECT 200, DOUBLE 201505

    UNION ALL

    SELECT 200, DOUBLE 201506

    UNION ALL

    SELECT 200, DOUBLE 201508

    UNION ALL

    SELECT 200, DOUBLE 201509

    UNION ALL

    SELECT 200, DOUBLE 201510

    UNION ALL

    SELECT 200, DOUBLE 201511

    UNION ALL

    SELECT 200, DOUBLE 201512

    UNION ALL

    SELECT 200, 201601 DOUBLE

    UNION ALL

    SELECT 200, DOUBLE 201602

    UNION ALL

    SELECT 300, DOUBLE 201503

    UNION ALL

    SELECT 300, DOUBLE 201504

    UNION ALL

    SELECT 300, DOUBLE 201505

    UNION ALL

    SELECT 300, DOUBLE 201506

    UNION ALL

    SELECT 300, DOUBLE 201507

    UNION ALL

    SELECT 300, DOUBLE 201508

    UNION ALL

    SELECT 300, DOUBLE 201509

    UNION ALL

    SELECT 300, DOUBLE 201510

    UNION ALL

    SELECT 300, DOUBLE 201511

    UNION ALL

    SELECT 300, 201601 DOUBLE

    UNION ALL

    SELECT 300, DOUBLE 201602

    UNION ALL

    SELECT 400, DOUBLE 201504

    UNION ALL

    SELECT 400, DOUBLE 201505

    UNION ALL

    SELECT 400, DOUBLE 201506

    UNION ALL

    SELECT 400, DOUBLE 201507

    UNION ALL

    SELECT 400, 201508 DOUBLE),

    -The Dataset to test ends

    -Hand with clause begins

    ResultSet

    AS (SELECT account_no,

    CASE

    WHEN COUNT)

    CASE WHEN dates IN (201503, 201602) THEN 1 END)

    COURSES (PARTITION BY account_no) = 2

    AND (COUNT (DISTINCT SUBSTR (dates, 4)))

    COURSES (PARTITION BY account_no) = 12

    OR COUNT (DISTINCT SUBSTR (dates, 4))

    COURSES (PARTITION BY account_no)<>

    AND COUNT (DISTINCT SUBSTR (dates, 1, 4))

    (PARTITION BY account_no) > 1

    THEN

    « Y »

    ON THE OTHER

    « N »

    END

    FLG

    THE dataset---> replace with your table name

    GROUP BY account_no, dates)

    SELECT DISTINCT Account_no

    FROM THE result set

    WHERE flg = 'Y ';

    -Hand with the ends of the clause

    ACCOUNT_NO

    -----------------------

    100

    300

    200

    See you soon,.

    Manik.

  • Find the 2nd Sunday of each month in a report

    Hello

    I have the data of EMP_Name and Join_Date. I have to build a dashboard report where

    1. In the dashboard, there is a command prompt. If I select a year and a month then, the report is expected to show that the data of the respective month.
    2. This report will show the employees who joined the company only after the 2nd Sunday of each month until the end of the month.

    Inputs/suggestions, how to build it?

    Thanks in advance.

    You have a question, Yes... a SQL query... OBIEE do not mean SQL but LSQL, your query will be not really usable like this...

    You're right, it seems that when the first day of the month is a Saturday he jump 1 week...

    The correct formula for the 3rd Friday is:

    TIMESTAMPADD (SQL_TSI_DAY, (14 + 6-CASE WHEN DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE)) = 7 THEN 0 END ELSE DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))), TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))

    If instead of CURRENT_DATE you want to use your own column date just to replace in the formula and it works.

  • How to find the first Sunday and the second Saturday of each month

    Hi all

    How to find the first Sunday and the second Saturday of each month

    Thank you

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    994122 wrote:

    Hello

    I need to pass the months parameter how to do this? like Jan, Feb etc... (one of those)

    Do you have a procedure?

    Should you output only for the months you passed in the parameter?

    The easiest way is to set the parameter as date. When you go such as p_date as DATE ' 2014-10-01', then you can

    PROCEDURE two_dates)

    p_date IN DATE

    p_first_sunday DATE

    p_second_saturday DATE

    )

    IS

    BEGIN

    p_first_sunday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-12', 'DAY'));

    p_second_saturday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-11', 'DAY')) + 7;

    END two_dates;

    Or you describe what you need.

  • How to get the second Monday of each month in a given date range?

    In Oracle forms, how to get the second Monday of each month in a given date range?

    I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?

    WITH month_range AS

    (

    SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month

    , TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month

    OF the double

    )

    SELECT NEXT_DAY (6 + ADD_MONTHS (first_month

    , LEVEL - 1

    )

    , 'MONDAY '.

    ) AS second_monday

    OF month_range

    CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)

    ;

    Thanks in advance.

    Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below

    SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.

    THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7

    END AS second_day

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • start date for each week of the month

    Dear members

    How can I find double, the start date of each week of the month in a year.
    beginning of the week is the word "Monday".


    year month week day date
    ----------------------------------------------------------------------------------------
    Monday, January 3, 2011 JAN 1, 2011
    2011 2 JAN Monday, January 10, 2011
    Monday, January 17, 2011 January 3, 2011
    JAN 4 2011 on Monday, January 24, 2011
    2011 to January 5 Monday, January 31, 2011


    Thank you

    teefu

    Hello

    You can use this:

    with t as  (select to_date ('01/01/2011', 'DD/MM/YYYY') start_date from dual)
    select  date_calc
    from (
            select  start_date,
                    (level-1)*7+trunc (start_date , 'D')+1   as date_calc
            from t
            connect by level <=53)
    where trunc(date_calc,'YYYY')=trunc(start_date,'YYYY') ;
    

    Kind regards
    Sylvie

Maybe you are looking for

  • I have an iPad and I try to download, I need help!

    I have an ipad and I am trying to download the google toolbar and why I have Firefox and when I try I get a Safari cannot download the answer. Help, please! I'm not that swavy with ipad, as you can tell and she also don't will not download to my MacB

  • MacBook 2006 does not recognize the Canvio Stor.e

    Hello world! I bought this external HDD Stor.e Canvio (2 TB usb2/3),The problem is that it only appears not on the macbook in 2006 (2 GB ram 2 GHz c2d OSX 10.4) I bought it for. But:The HARD drive is perfectly recognized by my macbook pro.Other exter

  • The lack of Windows Vista Security Center.

    My computer (Vista operating system) was attacked by the 'Vista Home Security 2012' malware. I cleaned the computer with difficulty he Utilities but I can't turn on my Windows Security Center. It is not even appear in 'Services '. Do I have to re - i

  • Can anyone provide an exclusive link for a 30 day trial of diskeeper?

    CAN ANYONE PROVIDE AN EXCLUSIVE FOR A 30 DAYS TRIAL LINK DISKEEPER (USER)? WHENEVER I HAVE A LINK, HE EVENTUALLY PAID OTHER DOWNLOAD PROGRAMS THAT IVE SPENT AGES UNINSTALL!

  • HOWTO reinstall microsoft photos app on Windows 8

    I uninstalled Microsoft photos app, because the update of the application did not work properly. Now, I can't reinstall the app, because it does not appear in the Windows store. 8 64-bit Windows. Help appreciated. Kind regards