Weeks of the month with Total

Hey,.

I try to display the weeks of the month based on values and a date.  I have a select statement that displays vertical to results, but I would like that they horizontally with the listed weeks. Below are the create table and insert instructions to help.  Once the start dates and end Dates are entered for one month, then the weeks should display with the counts for each Type Emp values and totals for each Type of Emp showing also. Any help is appreciated.  Thanks for taking a peek at my question.

-Toad for Oracle 12.5

CREATE TABLE TBL_EMP

  EMP_ID  NUMBER NOT NULL,

FK_EMP_TYPE_ID NUMBER ,

EMP_DATE DATE

INSERT INTO TBL_EMP

()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )

(1, 100, TO_DATE('10/14/2014', 'MM/DD/YYYY'));

INSERT INTO TBL_EMP

()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )

(2, 200, TO_DATE('10/12/2014', 'MM/DD/YYYY'));

INSERT INTO TBL_EMP

()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )

(3, 200, TO_DATE('10/8/2014', 'MM/DD/YYYY'));

INSERT INTO TBL_EMP

()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )

(4, 300, TO_DATE('10/15/2014', 'MM/DD/YYYY'));

INSERT INTO TBL_EMP

()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )

(5, 100, TO_DATE('10/12/2014', 'MM/DD/YYYY'));

INSERT INTO TBL_EMP

()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )

(6, 100, TO_DATE('9/9/2014', 'MM/DD/YYYY'));

 

SELECT * DE TBL_EMP;

-Can I display the vertical weeks but I would like that they horizontal

  SELECT 'WEEK ' || (TO_CHAR (EMP_DATE + 4, 'W')) WEEKS,

FK_EMP_TYPE_ID ,

   COUNT (FK_EMP_TYPE_ID) AS EMP_TYPE_COUNT

   FROM TBL_EMP

   WHERE EMP_DATE BETWEEN TO_DATE ( :P10_START_DATE, 'MM/DD/YYYY')

   AND NVL (TO_DATE ( :P10_END_DATE, 'MM/DD/YYYY'), SYSDATE)

GROUP BY 'WEEK ' || (TO_CHAR (EMP_DATE + 4, 'W')), FK_EMP_TYPE_ID

ORDER BY WEEKS;

-The values to enter for months

-P10_START_DATE 10/01/2014

-P10_END_DATE 31/10/2014

-Results

WEEK 2    200   1

WEEK 3    100   2

WEEK 3    200   1

WEEK 3    300   1

 

  SELECT FK_EMP_TYPE_ID , COUNT (*)

   FROM TBL_EMP

   WHERE EMP_DATE BETWEEN TO_DATE ( :P10_START_DATE ' MM/DD/YYYY '( )

   AND NVL (TO_DATE ( :P10_END_DATE, 'MM/DD/YYYY'), SYSDATE)

GROUP BY FK_EMP_TYPE_ID

ORDER BY FK_EMP_TYPE_ID ASC;

-Results

FK_EMP_TYPE_ID COUNT(*)

100                                  2

200                                  2

300                                  1

-Results and horizontal display I want

FK_EMP_TYPE_ID WEEK 1 WEEK 2 WEEK 3 WEEK 4 TOTALS

100                                0               0            2            0             2

200                                0               1            1            0             2

300                                0               0            1            0             1

Hello

Select

Here's one way:

WITH relevant_data AS

(

SELECT fk_emp_type_id

TO_CHAR (emp_date + 4, 'W') AS week_num - see note below

OF tbl_emp

WHERE the emp_date BETWEEN NVL (TO_DATE (: p10_start_date, ' MM/DD/YYYY'))

SYSDATE - TRUNC (SYSDATE) or

)

AND NVL (TO_DATE (: p10_end_date, ' MM/DD/YYYY'))

SYSDATE

)

)

SELECT p

week_1 + week_2 + week_3 + week_4 + week_5 AS totals

OF relevant_data

PIVOT (COUNT (*)

FOR week_num IN ('1' AS week_1

'2' AS week_2

'3' AS week_3

'4' AS week_4

'5' AS week_5

)

) p

ORDER BY fk_emp_type_id

;

Are you sure you want to add 4 days before calculating the week number?  If you're wondering the month of October 2014, for example, '1' of the week would include 1-3 October and from 28 to 31 October.  (4 days after October 28 is November 1, which is 1 week of November).

Tags: Database

Similar Questions

  • 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

  • get the first week of the month

    Hello
    How to get the first week of the month of request

    I tried this, but not gwtting

    SELECT THE DOUBLE TO_CHAR('09/30/2007','W')

    Thank you

    Published by: 896398 on January 18, 2012 03:17
    SQL> select to_char(to_date('07-12-2008', 'DD-MM-YYYY'), 'W') from dual; 
    
    T
    -
    1
    
    SQL> select to_char(to_date('14-12-2008', 'DD-MM-YYYY'), 'W') from dual; 
    
    T
    -
    2
    
    SQL> select to_char(to_date('23-12-2008', 'DD-MM-YYYY'), 'W') from dual;
    
    T
    -
    4
    

    HTH

    Kind regards
    NORTH CAROLINA

  • Last day of the month with the last minute of the day

    Hello
    I wonder about how to get the last day of the month with the last minute of this day(23:59). We can use the last_day function (DATE) to get the last date, but reminds me of the time of day when the function has been executed. But I want to have the last minute with my last date of the current month.

    Please inform.

    Thank you

    HP

    Hello

    Ora_bie wrote:
    Hello
    I wonder about how to get the last day of the month with the last minute of this day(23:59). We can use the last_day function (DATE) to get the last date, but reminds me of the time of day when the function has been executed. But I want to have the last minute with my last date of the current month.

    In fact, it returns at the same time as the argument you pass; But whatever it is, is not what you want.

    This will return the last day of the month that contains the DATE 23:59 (or 23:59) dt:

    SELECT  ADD_MONTHS ( TRUNC (dt, 'MONTH')
                 , 1
                 ) - (1 / (24 * 60))
    FROM    dual
    ;
    

    TRUNC (dt, 'MONTH') is 00:00 on the first day of the month that contains dt.
    ADD_MONTHS (TRUNC (dt, 'MONTH'), 1) is from 00:00 the first day of the month following the one containing dt.
    ADD_MONTHS (TRUNC (dt, 'MONTH'), 1)-(1 / (24 * 60)) is a minute earlier.
    (Since there are 24 hours, each with 60 minutes, every day, 1 / (24 * 60) days is identical to a minute.)

    Another (less clear, in my opinion) way to get the same results is:

    TRUNC (LAST_DAY (dt)) + (1439/1440)  -- 1440 minutes = 1 day
    
  • How to calculate this column (the last week of the month)?

    I have a request where it shows a few months of calculations of sage

    ex. This report is for Dec-2010

    statement line. A reduced rate. Approved rate. Last week declined the rate |
    -------------------------
    Asia report | ------20%----- | -----45%-------- | --------4%------ |
    Africa report | ------44% -----| -----21%-------- | ------12%-------|

    I'm figuring the column rate declined last week . The logic is simply not coming to my mind.
    Can someone suggest me how can I calculate this?

    We'll see. This report at any time after the previous month running has closed...

    (1) TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE) will give you the last day of the previous month.

    (2) TIMESTAMPADD (SQL_TSI_DAY, DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) *-1, TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) will give you the Saturday before the last week of the month.

    (3) TIMESTAMPADD (SQL_TSI_DAY, 1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) *-1, TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE))) will give you the Sunday of the last week of the previous month.

    Now that you have the start of the last day of the previous week, you can create your filter... It will be "(between 3) and 1)" above... "

  • How to get the Date in month based on week of the month.

    Hi gurus,

    I have provided.

    Quarter (Q) = > 1 (Jan - Mar), 2 (April-June), 3 (July-September), 4 (October-December).

    Months (M) = > Jan = 1, Feb = 2, Mar = 3 in the 1st quarter.

    ARP = 1, may = 2, Jun = 3 in the 2nd quarter,

    Jul = 1, August = 2, Ms = 3 in Q3,

    Oct 1 Nov = = 2, Dec = 3 in the 4th quarter

    If I give Q = 3, M = 3, W = 1 day = Fri so I get 6-Sep-13

    Similarly, if I give Q = 2, M = 1, O = 3, day = game so I get 18 April 13.

    Could someone help me higher and higher.

    Concerning

    Sanjeev

    Believing that when you say you want to say that it is 1 - 5 in a month with the 1st day of the month as the beginning of the 1st week of the week. You can try this.

    SQL > t
    2 as
    (3)
    4. Select q 3, 3 m, 1 w, 'Ven' d
    5 double
    6 union
    7 all the
    8. Select q 2, 1 m, 3 w, d 'game '.
    9 double
    10)
    11. Select q, m, w, d, d_day
    12 years of)
    13 select y + (level - 1) d_day
    14, ceil (extract (day of cast (y + (level - 1) as timestamp)) / 7) week_7_day
    15                   , t.*
    16 of)
    17 select add_months (trunc (sysdate, 'year') (q * 3-3) +(m-1)) y
    18                             , t.*
    19 t
    20                     ) t
    21 connect
    22 by level<= last_day(y)="" -="" y="" +="">
    23 and prior y = y
    dbms_random.value (24 and prior) is not null
    25         )
    where the 26 w = week_7_day
    27 and substr (to_char (d_day 'day'), 1, 3) = lower (d);

    Q M W D D_DAY
    ---------- ---------- ---------- --- ---------
    2 1 3 Friday 18 April 13
    3 3 1 Fri 06-SEP-13

    SQL >

  • Group by month and also to see the month with no record

    Hi - a mental block important this morning, pretty sure it's a simple one types just need of you experts to point me in the right direction...

    Using the data from the example below, I just need to generate a report to show the username, mon-yy, number of transactions. I need to show the 12 months, with a zero if there is no transaction.

    I don't know if it's the right approach, but I use a subquery to generate 12 months, like obvisouly they aren't in transaction data. The fact that I have to_char against the kind of subquery to set the alarm bells ringing, I think that there is a better solution, but as I say, mental block.

    The query at the end was to show the thing of subquery works, but for the life of me I can't think today how to extend this option to include the user ID and give me the desired result (bottom code block).

    Frustrating when it should be relatively simple.

    Thanks in advance to all: o)
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
    create table trans (pkid number, userid number, transdate date);
    
    insert into trans values (1, 10, sysdate-300);
    insert into trans values (2, 10, sysdate-100);
    insert into trans values (3, 20, sysdate-100);
    insert into trans values (4, 20, sysdate-50);
    insert into trans values (5, 20, sysdate-20);
    commit;
    
    select * from trans;
    
          PKID     USERID TRANSDATE
    ---------- ---------- ---------
             1         10 05-AUG-10
             2         10 21-FEB-11
             3         20 21-FEB-11
             4         20 12-APR-11
             5         20 12-MAY-11
    
    select sub.mon, count(t.transdate) from trans t,
    (select to_char(add_months(sysdate, -level),'MON-YY') as mon
    from dual
    connect by level <=12) sub
    where sub.mon = to_char(transdate(+),'MON-YY')
    group by sub.mon
    order by to_date(sub.mon,'MON-YY')
    /
    
    MON    COUNT(T.TRANSDATE)
    ------ ------------------
    JUN-10                  0
    JUL-10                  0
    AUG-10                  1
    SEP-10                  0
    OCT-10                  0
    NOV-10                  0
    DEC-10                  0
    JAN-11                  0
    FEB-11                  2
    MAR-11                  0
    APR-11                  1
    MAY-11                  1
    
    12 rows selected.
    Desire:
    10  JUN-10  0
    10  JUL-10  0
    10  AUG-10  1
    ...and so on until...
    10  MAY-11  0
    
    20  JUN-10  0
    20  JUL-10  0
    20  AUG-10  0
    ...and so on until...
    20  FEB-11  1
    20  MAR-11  0
    20  APR-11  1
    20  MAY-11  1

    Hello

    This is what a Partitionné Outer Join :

    select        sub.mon
    ,        count (t.transdate)
    from        (
              select      to_char ( add_months (sysdate, -level)
                        , 'MON-YY'
                        ) as mon
              from      dual
              connect by      level      <= 12
           ) sub
    left outer join trans     t     PARTITION BY (t.userid)
                        ON      sub.mon = to_char (transdate,'MON-YY')
    group by  t.userid
    ,       sub.mon
    order by  t.userid
    ,       to_date (sub.mon,'MON-YY')
    ;
    

    A standard outer join ensures that you will get each row of the table of conduct displayed at least once. But you want each line of void poster n times, where n is the number of distinct identifiers in t. "PARTITION BY t.userid" means "treat each distinct value of the user name as a separate table" and the results will all be clauses together.

    There were new partitioned outer joins in Oracle 10. Previously, you had to form a set of distinct values for the user name, then the join cross-who with the distinct void months and finally outer join for the actual data.

  • PPR report, how to display the label with TOTAl

    Hello


    How can I view PPR report, how the display label with as TOTAl

    [http://apex.oracle.com/pls/apex/f?p=267:30:]


    Thank you

    Published by: 805629 January 6, 2011 03:34

    Hello

    Report RPP:

    Select 'Yes' to the point 'Enable partial Refresh of Page' region 'Layout and Pagination' report of the attributes of this report.

    For the display Label with TOTAL:

    Use 'Break the formatting' region in relation to the attributes of this report.

    Kind regards

    Patel Kartik
    ------------------------------------------------------------------------
    http://patelkartik.blogspot.com/
    http://Apex.Oracle.com/pls/Apex/f?p=9904351712:1

  • calculation of the week and the month of the column date

    I have 3 data as column
    with tab as 
    (
      select 'Topshop' brand, '10-JUL-11' deliverydate, '100' qty from dual union all
      select 'Topshop' brand, '10-JUL-11' deliverydate, '400' qty from dual union all
      select 'NewSita' brand, '11-JUL-11' deliverydate, '200' qty from dual union all
      select 'LaGress' brand, '12-JUL-11' deliverydate, '300' qty from dual union all
      select 'LaGress' brand, '10-AUG-11' deliverydate, '100' qty from dual union all
      select 'LaGress' brand, '11-AUG-11' deliverydate, '200' qty from dual union all
      select 'Topshop' brand, '12-AUG-11' deliverydate, '300' qty from dual union all
      select 'NewSita' brand, '10-SEP-11' deliverydate, '100' qty from dual union all
      select 'Topshop' brand, '11-SEP-11' deliverydate, '200' qty from dual union all
      select 'NewSita' brand, '12-SEP-11' deliverydate, '300' qty from dual
    ) select * from tab
    I need to convert it to 4 columns

    Brand | Month | Week (start date). Amount (sum)

    Please let me know what are the options I have, in particular the calculation of date and time functions available to solve these problems.

    Thank you
    w\

    Check this box

    with tab as
    (
    Select the option 'Topshop' brand, July 10, 11 'deliverydate, ' 100' qty of any union double
    Select the option 'Topshop' brand, July 10, 11 'deliverydate, ' 400' qty of any union double
    Select the option "NewSita" brand, 11 July 11 'deliverydate, ' 200' qty of any union double
    Select "brand the LaGress, 12 July 11' deliverydate, '300' qty of union double all the»
    Select "brand the LaGress, 10 Aug 11' deliverydate, '100' qty of union double all the»
    Select "brand the LaGress, 11 Aug 11' deliverydate, '200' qty of union double all the»
    Select the option 'Topshop' brand, 12 Aug 11 'deliverydate, ' 300' qty of any union double
    Select the brand 'NewSita',' 10-SEP-11 deliverydate, '100' qty of all double union
    Select the option 'Topshop' brand,' 11-SEP-11 deliverydate, '200' qty of any union double
    Select the option "NewSita" brand, deliverydate, '300' qty of the double' 12-SEPT-11
    ) select the brand, deliverydate, NEXT_DAY (to_date (deliverydate, 'DD-MON-yy'), "LUN")-7, Qty tab.

  • Apex SQL question - weeks of the month

    I have a sql question.
    I want to create a dynamic list.

    If the user select may2009, then I want a dynamic list of show

    04/27/2009-05/03/2009
    05/04/2009-05/10/2009
    05/11/2009-05/17/2009
    05/18/2009-05/24/2009
    05/25/2009-05/31/2009

    If the user selects Jun 2009, then the list will be
    06/01/2009-06/07/2009
    06/08/2009-06/14/2009
    06/15/2009-06/21/2009
    06/22/2009-06/28/2009
    06/29/2009-07/05/2009

    Thank you.

    Using this SQL statement, you can get this list:

    SELECT w_start || ' - ' || w_end d, w_start r
      FROM (SELECT     (week_start_list + (LEVEL - 1) * 7) + 1 w_start,
                       week_start_list + (LEVEL) * 7 w_end
                  FROM (SELECT TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                               'mm'
                                              ),
                                        'IW'
                                       ) week_begin,
                               TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                      'mm'
                                     ) m_begin,
                               TO_CHAR
                                  (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm'),
                                   'd'
                                  ) day_month_begin,
                               TO_CHAR
                                  (TRUNC (ADD_MONTHS (TO_DATE (:my_date,
                                                               'dd.mm.yyyy'
                                                              ),
                                                      1
                                                     ),
                                          'mm'
                                         ),
                                   'IW'
                                  ) week_end,
                               TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                                  1
                                                 ),
                                      'mm'
                                     ) m_end,
                               TO_CHAR
                                  (TRUNC (ADD_MONTHS (TO_DATE (:my_date,
                                                               'dd.mm.yyyy'
                                                              ),
                                                      1
                                                     ),
                                          'mm'
                                         ),
                                   'd'
                                  ) day_month_end,
                                 TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                        'mm'
                                       )
                               - TO_NUMBER
                                          (TO_CHAR (TRUNC (TO_DATE (:my_date,
                                                                    'dd.mm.yyyy'
                                                                   ),
                                                           'mm'
                                                          ),
                                                    'd'
                                                   )
                                          ) week_start_list,
                                 TRUNC
                                    (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                                 1
                                                ),
                                     'mm'
                                    )
                               + TO_NUMBER
                                    (TO_CHAR
                                        (TRUNC
                                              (ADD_MONTHS (TO_DATE (:my_date,
                                                                    'dd.mm.yyyy'
                                                                   ),
                                                           1
                                                          ),
                                               'mm'
                                              ),
                                         'd'
                                        )
                                    )
                               - 1 week_end_list
                          FROM DUAL)
            CONNECT BY LEVEL <=
                          (SELECT   TO_NUMBER
                                       (TO_CHAR
                                           (TRUNC
                                               (ADD_MONTHS (TO_DATE (:my_date,
                                                                     'dd.mm.yyyy'
                                                                    ),
                                                            1
                                                           ),
                                                'mm'
                                               ),
                                            'IW'
                                           )
                                       )
                                  - TO_NUMBER
                                          (TO_CHAR (TRUNC (TO_DATE (:my_date,
                                                                    'dd.mm.yyyy'
                                                                   ),
                                                           'mm'
                                                          ),
                                                    'IW'
                                                   )
                                          )
                             FROM DUAL))
    

    It is a question of SQL and has nothing to do with the Apex.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    -------------------------------------------------------------------

  • Calendar events hotmail disappeared days corresponding to the monthly calendar

    My hotmail calendar displays more events that I posted in my monthly calendar display.  They appear at the far left of the first day of each week in the monthly calendar.  They appear correctly in all other views of the calendar.  This just happened recently.  What can I do about it?

    Hello

    I'm sorry, but we cannot help with hotmail problems in these forums in response to vista

    Please repost your question in hotmail in the hotmail link below forums

    http://windowslivehelp.com/product.aspx?ProductID=1

    Forums
  • Monday the 1st business day of the month of 15 before and after 15.

    I want to choose the 1st Monday with the business day (Y) of a month (january), owned by the 15th of the month and after the 15th of the month.
    Whereas it should be 2 folders, 1 record should be before the 15th of the month with the word 'Monday' & Holiday (N) and 2nd record should be based on the 15th of the month
    with the word 'Monday' & Holiday (N).

    Table:-holiday
    Column
    ---------
    Time_Date - holiday - Time_Day
    2011-01-01 00:00:00 - N - Tuesday

    Please let me know the oracle query.

    Thanks and greetings
    R Rodriguez

    Edited by: 880353 August 19, 2011 05:14

    It's almost like this... just a matter of playing with the SQL to reorganize the command:

    Select
    min (case when TIME_DATE between trunc(sysdate,'MM') and trunc (sysdate, 'MM') + 13 and)
    H.HOLIDAY = ' only then end TIME_DATE to another null) «FIRST»,
    min (case when TIME_DATE between trunc (sysdate, 'MM') + 14 and last_day (sysdate) and)
    H.HOLIDAY = ' only then end TIME_DATE to another null) "FIRST > = 15.
    Holiday h.
    (select next_day (trunc(sysdate, 'MONTH')-1, 'Monday') + 7 *(level-1) double DD
    connect by level<= 5)="">
    where M.DD = h.TIME_DATE

  • How to divide the monthly amount in weeks no fracture

    Hi, I'm developing a quarterly report where there will be 13 weeks in a quarter (always) and the need to display amounts against only 13 weeks.

    First month 4 weeks, 2 months 4 weeks and 3 months was 5 weeks all the time. I have a data dimension table that will tell me the number of the week (Col1) and the number of months (col2) this week belongs to...

    My problem is that I have aggregated at the level of the month in the table amounts. I divide these monthly amounts in weekly amounts.

    My data:

    Data bucketQuantities
    01/02/201415
    01/03/20145
    01/04/20144

    Desired output:

    MonthWeekQuantities
    01/02/201414
    01/02/201424
    01/02/201434
    01/02/201443
    01/03/201452
    01/03/201461
    01/03/201471
    01/03/201481
    01/04/201491
    01/04/2014101
    01/04/2014111
    01/04/2014121
    01/04/2014130

    Thank you

    Hello

    To finish of Frank post (and using its formula), here's a way to get your results (and extend and adapt for your quarterly report):

    WITH bucket LIKE)

    SELECT ' 01 /' 02/2014 Mon, 15 amount OF double UNION ALL

    SELECT ' 01 / 03/2014 ', 5 double UNION ALL

    SELECT ' 01 /' 04/2014, 4 dual FROM

    ),

    mm AS)

    SELECT my, quantity, rownum bucket month_no

    ),

    week AS)

    N SELECT rownum FROM dual CONNECT BY level<=>

    )

    SELECT my 'months',

    ROW_NUMBER() over (ORDER BY Mon, n) 'week ',.

    WK n,

    CASE

    WHEN n<= mod="" (quantity,="" decode="" (month_no,="" 3,="" 5,="">

    THEN CEIL (quantity / DECODE (month_no, 3, 5, 4))

    ANOTHER FLOOR (amount / DECODE (month_no, 3, 5, 4))

    END "quantities".

    OF the week, mm

    WHERE month_no = 3

    OR (month_no (1,2) AND n)<=>

    )

    ORDER BY month_no, wk;

  • Breaking a year in coming weeks of beginning and end Dates (parameters) and first and last day of the month

    Hello people:

    I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.

    Any help or pointers would be great!

    Thank you!

    Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).

    The request in hand:

    SELECT first_thursday + (7 * (LEVEL - 1))   AS week_start_date,
                     first_thursday + (7 * LEVEL) - 1    AS  week_end_date
    FROM
    (
      SELECT TRUNC(p_from_date + 4, 'IW') - 4   AS first_thursday, -- Week should start the pre ceeding THURSDAY based on the Start Date
                      TRUNC( p_to_date + 4,  'IW') - 5     AS last_wednesday
      FROM
      (
        SELECT to_date('01-JAN-2013') AS p_from_date,
                        NVL(to_date('31-DEC-2013'), SYSDATE) AS p_to_date
        FROM     dual
      ) parms
    ) end_points
    CONNECT BY LEVEL <= ( last_wednesday + 1 - first_thursday)/7;
    

    Currently, this is the result I get (I'm only including the months of January and December here).

    Week_Start_Date     Week_End_Date
    27-DEC-12                02-JAN-13
    03-JAN-13                 09-JAN-13
    10-JAN-13                 16-JAN-13
    17-JAN-13                 23-JAN-13
    24-JAN-13                 30-JAN-13
    31-JAN-13                 06-FEB-13
    

    December:

    28-NOV-13               04-DEC-13
    05-DEC-13              11-DEC-13
    12-DEC-13              18-DEC-13
    19-DEC-13              25-DEC-13
    

    What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:

    January:

    01-JAN-13              02-JAN-13
    03-JAN-13              09-JAN-13
    10-JAN-13             16-JAN-13
    17-JAN-13             23-JAN-13
    24-JAN-13             30-JAN-13
    31-JAN-13             31-JAN-13
    

    February:

    01-FEB-13    06-FEB-13
    07-FEB-13    13-FEB-13
    14-FEB-13    20-FEB-13
    21-FEB-13    27-FEB-13
    28-FEB-13    28-FEB-13
    

    November:

    31-OCT-13    06-NOV-13
    07-NOV-13    13-NOV-13
    14-NOV-13    20-NOV-13
    21-NOV-13    27-NOV-13
    28-NOV-13    04-DEC-13
    

    December:

    01-DEC-13           04-DEC-13
    05-DEC-13           11-DEC-13
    12-DEC-13          18-DEC-13
    19-DEC-13          25-DEC-13
    26-DEC-13          31-DEC-13
    

    Hello

    Roxyrollers wrote:

    Hello people:

    I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.

    Any help or pointers would be great!

    Thank you!

    Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).

    The request in hand:

    1. First_thursday SELECT + (7 * (LEVEL - 1)) AS week_start_date,
    2. first_thursday + (7 * LEVEL)-1 AS week_end_date
    3. Of
    4. (
    5. SELECT TRUNC (p_from_date + 4, 'IW') - 4 AS first_thursday,-week should start to perform the pre-mounted THURSDAY based on the Start Date
    6. TRUNC (p_to_date + 4, 'IW') - 5 AS last_wednesday
    7. Of
    8. (
    9. SELECT to_date('01-JAN-2013') AS p_from_date,
    10. NVL (to_date('31-Dec-2013'), SYSDATE) AS p_to_date
    11. OF the double
    12. ) parms
    13. ) end_points
    14. CONNECT BY LEVEL<= (="" last_wednesday="" +="" 1="" -="">

    Currently, this is the result I get (I'm only including the months of January and December here).

    1. Week_Start_Date Week_End_Date
    2. DECEMBER 27, 12 2 JANUARY 13
    3. JANUARY 3, 13 JANUARY 9, 13
    4. 10 JANUARY 13 JANUARY 16, 13
    5. 17 JANUARY 13 23 JANUARY 13
    6. 24 JANUARY 13 30 JANUARY 13
    7. 31 JANUARY 13 FEBRUARY 6, 13

    December:

    1. NOVEMBER 28, 13 4 DECEMBER 13
    2. 5 DECEMBER 13 DECEMBER 11, 13
    3. 12 DECEMBER 13 18 DECEMBER 13
    4. 19 DECEMBER 13 DECEMBER 25, 13

    What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:

    January:

    1. JANUARY 1, 13 2 JANUARY 13
    2. JANUARY 3, 13 JANUARY 9, 13
    3. 10 JANUARY 13 JANUARY 16, 13
    4. 17 JANUARY 13 23 JANUARY 13
    5. 24 JANUARY 13 30 JANUARY 13
    6. 31 JANUARY 13 JANUARY 31, 13

    February:

    1. 1ST FEBRUARY 13 FEBRUARY 6, 13
    2. 7 FEBRUARY 13 FEBRUARY 13, 13
    3. 14 FEBRUARY 13 FEBRUARY 20, 13
    4. 21 FEBRUARY 13 FEBRUARY 27, 13
    5. 28 FEBRUARY 13 FEBRUARY 28, 13

    November:

    1. 31 OCTOBER 13 NOVEMBER 6, 13
    2. 7 NOVEMBER 13 NOVEMBER 13, 13
    3. 14 NOVEMBER 13 NOVEMBER 20, 13
    4. 21 NOVEMBER 13 NOVEMBER 27, 13
    5. NOVEMBER 28, 13 4 DECEMBER 13

    December:

    1. 1ST DECEMBER 13 DECEMBER 4, 13
    2. 5 DECEMBER 13 DECEMBER 11, 13
    3. 12 DECEMBER 13 18 DECEMBER 13
    4. 19 DECEMBER 13 DECEMBER 25, 13
    5. 26 DECEMBER 13 DECEMBER 31, 13

    Why the "weeks" in November, have all 7 days, while the "weeks" in the first or the last week in the other month usually have less?  (For example, February 28 is a 'week' alone.)

    The following works for the other months:

    WITH all_days AS

    (

    SELECT DATE "2013-01-01' + LEVEL - AS a_date 1

    OF the double

    CONNECT BY LEVEL<=>

    )

    SELECT DISTINCT

    More GRAND (TRUNC (a_date + 4, 'IW') - 4)

    , TRUNC (a_date, 'MONTH')

    ) AS week_begin

    , The LEAST (TRUNC (a_date + 4, 'IW') + 2

    TRUNC (LAST_DAY (a_date))

    ), Week_end

    Of all_days

    ORDER BY week_begin

    ;

    Output:

    WEEK_BEGIN WEEK_END

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

    January 1, 2013 January 2, 2013

    January 3, 2013 January 9, 2013

    January 10, 2013 January 16, 2013

    January 17, 2013 January 23, 2013

    January 24, 2013 January 30, 2013

    January 31, 2013 January 31, 2013

    February 1, 2013 February 6, 2013

    February 7, 2013 February 13, 2013

    February 14, 2013 February 20, 2013

    February 21, 2013 February 27, 2013

    February 28, 2013 February 28, 2013

    ...

    November 1, 2013 November 6, 2013

    November 7, 2013 November 13, 2013

    November 14, 2013 November 20, 2013

    November 21, 2013 November 27, 2013

    November 28, 2013 November 30, 2013

    December 1, 2013 December 4, 2013

    December 5, 2013 December 11, 2013

    December 12, 2013 December 18, 2013

    December 19, 2013 December 25, 2013

    26 December 2013 31 December 2013

  • How do the 3rd week (business day) of the month in a date range?

    Hello


    I'm trying to find the 3rd day of the work week of each month in a given range of dates.  How is it possible in a SQL query? Thank you in advance.

    Hello

    Here's one way:

    SELECT first_day + BOX

    WHEN TO_CHAR (first_day, "DY") IN ("play", "Fri", "SAT")

    THEN 4

    WHEN TO_CHAR (first_day, "DY") ("SUN")

    THEN 3

    2 ELSE

    END AS workday_3

    DE)

    SELECT ADD_MONTHS (first_month

    , LEVEL - 1

    ) AS first_day

    DE)

    SELECT TO_DATE ('Sep 2013', 'My YYYY') AS first_month

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

    OF the double

    )

    CONNECT BY LEVEL<= 1="" +="" months_between="" (last_month,="">

    )

    ORDER BY workday_3

    ;

    In another thread,.

    https://community.Oracle.com/thread/3513808

    you said that you had problems using a WITH clause, so I used online views instead of CLAUSES.

    With the above parameters, the result is:

    WORKDAY_3

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

    Wed 04-Sep-2013

    Set of 3 October 2013

    November 5, 2013 Mar

    Wednesday, December 4, 2013

    Fri January 3, 2014

Maybe you are looking for

  • Export the addresses of each received mail

    Hello! I received emails from 60 on my Inbox and I want to export all the addresses on the 'from' field of these mails to create a list/txt/csv file. How can I do?

  • Satellite P50-A-144 - 8.1 Win Win 10 upgrade affect warranty?

    Hello as announced, at the end of July, 2015 the new Windows 10 will be available for download and installation. My laptop Toshiba P - 50 a - 144 with windows 64-bit home pre installed (OEM Toshiba) 8.1 received the message of the Windows Update proc

  • Leakage current? Battery indicator?

    My new Ideapad Y530 feel that there is a leakage current very low activity or subtle vibration when I touch the front of the keyboard Panel (the metal surface on each side of the key touch, in front of the keyboard). This feeling is present only when

  • Image background 'Storm' blackBerry Smartphones Original; He's already on the phone

    Just noticed today while my phone was querky move from portrait to landscape and everything by plugging in my USB key, the original image of the "Storm" appeared briefly. Anyway, just thought I'd post.

  • User account that I not create in windows 8

    There is a user account that I not create in windows 8. What is everything? How this account was created, by whom, and why you can't get rid of it? He keeps reappearing even if you change the name and delete it. My computer is HP, win8 preinstalled,