Generating lines separated for each month in a date range

Basically I have a row of data, for example:

ID - start_date - end_date

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

XXA 1/23/14-3/12/14

And I want to create a line for each month between the arguments start_date and end_date, for each ID, for example:

ID - month - year

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

XXA January 2014

XXA February 2014

XXA March 2014

What is the best and most effective way to do it? I thought using a slider, but once the table is created, I need to join the other than this one. I am new to oracle, and I don't know if you can join the other tables after completing a cursor and create a temporary table. Any help would be greatly appreciated.

so... go with this:

WITH DATA AS (SELECT "XXA' ID, DATE '2014-01-23' start_date, DATE' 2014-12-03' end_date FROM dual)

UNION ALL

SELECT "XX(B)' ID, DATE '2013-05-23' start_date, DATE' 2014-07-03' end_date dual FROM

UNION ALL

SELECT "XXC" ID, DATE '2012-01-23' start_date, DATE' 2013-12-03' end_date FROM dual)

minmax AS (SELECT MIN (TRUNC(START_DATE,'Month')) AS minmon

MAX (trunc(end_date,'Month')) AS maxmon

DATA)

, themons AS (SELECT add_months (minmon, LEVEL - 1) LIKE my)

OF minmax

CONNECT BY add_months (minmon, LEVEL - 1)<=>

SELECT d.id, m.mon

DATA d

JOIN themons m ON (m.mon BETWEEN trunc(d.start_date,'Month') AND trunc (d.end_date, 'Month'))

order by d.id, m.mon

/

Tags: Database

Similar Questions

  • How to display each month between the date range

    I want a query that gives me the number of months between two dates given for example, if I going January 1, 2009 and April 1, 2009 then I should get on February 1, 2009 and March 1, 2009 in my trips

    Thank you very much

    Srix wrote:
    Thanks for the request

    It is not working do not when the effective date is differs from that in a year i.e start date January 1, 2009 and end date February 1, 2009, that it does not give u then required result

    I don't know what you mean? The dates are in the same year.

  • write 1 d digital table in a binary file and start a new line or insert a separator for each loop writing file

    Hello:

    I'm fighting with digital table of 1 d writeing in a binary file and start a new line or insert a separator for each loop writing file. So for each loop, it runs, LABVIEW code will collect a table 1 d with 253 pieces of a spectrometer. When I write these tables in the binay file and the following stack just after the previous table (I used MATLAB read binary file). However whenever if there is missing data point, the entire table is shifted. So I would save that table 1-d to N - D array and N is how many times the loop executes.

    I'm not very familiar with how write binary IO files works? Can anyone help figure this? I tried to use the file position, but this feature is only for writing string to Bodet. But I really want to write 1 d digital table in N - D array. How can I do that.

    Thanks in advance

    lawsberry_pi wrote:

    So, how can I not do the addition of a length at the beginning of each entry? Is it possible to do?

    On top of the binary file write is a Boolean entry called ' Prepend/chain on size table (T) '.  It is default to TRUE.  Set it to false.

    Also, be aware that Matlab like Little Endian in LabVIEW by default Big Endian.  If you probably set your "endianness" on writing binary file as well.

  • Use of user track in buckets of 48 hours for each month

    I have an obligation to follow the use by the user in buckets of 48 hours for each month. For example, from midnight on 1st Oct, create buckets of 48 hours thanks to 23:59 on 31 Oct. For each user, how many times they use the system in each bucket 48 hours? I try to avoid PL/SQL, if I can so right SQL is preferred. Thank you very much in advance for your help.

    Usage_Table (sample data)

    ID User_Name Create_DateTime

    This last 100 10/01/11 00:01:58
    This last 101 01/10/11 01:02:31
    102 user_B 02/10/11 14:44:32
    This last 103 04/10/11 08:21:11
    This last 104 04/10/11 03:10:20
    105 user_B 05/10/11 12:50:30
    106 and user_a 07/10/11 13:45:10
    107 and user_a 07/10/11 18:22:08


    Example of output

    User_name From_DateTime To_DateTime Number_Of_System_Uses
    This last 10/01/11 00:00:00 02/10/11 23:59:59 2
    user_A 03/10/11 00:00:00 04/10/11 23:59:59 2
    user_B 10/01/11 00:00:00 02/10/11 23:59:59 1
    user_B 10/04/11 00:00:00 05/10/11 23:59:59 1
    and user_a 10/06/11 00:00:00 07/10/11 23:59:59 2

    Hello

    JoeCO wrote:
    ... I tried the outer join, but did not see the number 0. I'll keep playing with it.

    Sorry, my mistake. It was not nearly as simple as I said earlier. JOIN EXTERNAL means that all ranks of the cntr will appear in the result set at least once, but we need every line of cntr appear joining each month and user_name at least once, we can do with a partitioned outer join:

    WITH     cntr     AS
    (
         SELECT     2 * (LEVEL - 1) AS low_val
         ,     2 *  LEVEL     AS high_val
         FROM     dual
    --     CONNECT BY     LEVEL     <= 16     -- Max buckets in any month
         CONNECT BY     LEVEL     <=  4     -- For testing only
    )
    ,     got_month_start     AS
    (
         SELECT     user_name
         ,     create_datetime
         ,     TRUNC (create_datetime, 'MONTH')     AS month_start
         FROM     t_usage
    )
    SELECT       u.user_name
    ,       u.month_start + c.low_val     AS bucket_start_date
    ,       u.month_start + c.low_val
                   + 2
                   - (1 / (24 * 60 * 60))
                             AS bucket_end_date
    ,       COUNT (u.create_datetime)     AS number_of_system_uses
    FROM             cntr            c
    LEFT OUTER JOIN      got_month_start  u  PARTITION BY ( u.user_name
                                    , u.month_start
                                    )
                             ON  ( u.create_datetime
                                 - u.month_start
                                 )     BETWEEN     c.low_val
                                  AND     c.high_val
    GROUP BY  u.user_name
    ,       u.month_start
    ,       c.low_val
    ORDER BY  u.user_name
    ,       bucket_start_date
    ;
    

    As you can see, I also moved the calculation of TRUNC (create_datetime, 'MONTH') in a subquery.
    I only showed the frist 4 buckets, just to simplify somewhat the exit during the original trial. The result is:

    `                                              NUMBER
                                                     _OF_
                                                   SYSTEM
    USER_N BUCKET_START_DATE   BUCKET_END_DATE      _USES
    ------ ------------------- ------------------- ------
    user_A 10/01/2011 00:00:00 10/02/2011 23:59:59      2
    user_A 10/03/2011 00:00:00 10/04/2011 23:59:59      2
    user_A 10/05/2011 00:00:00 10/06/2011 23:59:59      0
    user_A 10/07/2011 00:00:00 10/08/2011 23:59:59      0
    
    user_B 10/01/2011 00:00:00 10/02/2011 23:59:59      1
    user_B 10/03/2011 00:00:00 10/04/2011 23:59:59      0
    user_B 10/05/2011 00:00:00 10/06/2011 23:59:59      1
    user_B 10/07/2011 00:00:00 10/08/2011 23:59:59      0
    
    user_C 10/01/2011 00:00:00 10/02/2011 23:59:59      0
    user_C 10/03/2011 00:00:00 10/04/2011 23:59:59      0
    user_C 10/05/2011 00:00:00 10/06/2011 23:59:59      0
    user_C 10/07/2011 00:00:00 10/08/2011 23:59:59      2
    
  • After purchasing the cloud creative and used for 2 months (for example), so I don't use it for 3 months. How is it? I don't have to pay the tariff for each month, or is it possible to only pay when I use it again? To resume: if I use it for 5 months a

    After purchasing the cloud creative and used for 2 months (for example), so I don't use it for 3 months. How is it? I don't have to pay the tariff for each month, or is it possible to only pay when I use it again? To resume: if I use it for 5 months a year, I have to pay for only those 5 or 12 months?

    No, if you have a subscription according to the type of subscription, you will have to pay each month or year until that you cancel.

    If you think you would use the apps for only three months, then you will not need three months, then our month to month plan would be best for you because it can be cancelled at any time it does not come with an annual contract for more information see the link below

    Adobe - General conditions of subscription

    Kind regards

    Bani

  • How to reset the value of line number for each header

    Hi all

    I need to reset the line number for each header values.

    create table header_table (header_value varchar2 (100));

    create table line_table (header_value varchar2 (100), number line_number);

    insert into header_table values ('ALAOF');

    insert into header_table values ('ALAOO');

    insert into line_table values('ALAOF',1);

    insert into line_table values('ALAOF',2);

    insert into line_table values('ALAOF',3);

    insert into line_table values('ALAOF',4);

    insert into line_table values('ALAOF',5);

    insert into line_table values('ALAOO,6);

    insert into line_table values('ALAOFO,7);

    insert into line_table values('ALAOO',8);

    insert into line_table values('ALAOO',9);

    insert into line_table values('ALAOO',10);

    insert into line_table values('ALAOO',11);

    insert into line_table values('ALAOO',12);

    Commit;

    TABLE HEADER_:

    header value

    ALAOF

    TRECYBEL

    LINE TABLE:

    header value line_number

    ALAOF 1

    ALAOF 2

    ALAOF 3

    ALAOF 4

    ALAOF 5

    TRECYBEL 6

    TRECYBEL 7

    TRECYBEL 8

    TRECYBEL 9

    TRECYBEL 10

    TRECYBEL 11

    TRECYBEL 12

    But looks like I got out of line below table

    LINE TABLE:

    header value line_number

    ALAOF 1

    ALAOF 2

    ALAOF 3

    ALAOF 4

    ALAOF 5

    TRECYBEL 1 <-reset the beginning of line number with 1 with different header value

    TRECYBEL 2

    TRECYBEL 3

    TRECYBEL 4

    TRECYBEL 5

    TRECYBEL 6

    TRECYBEL 7

    Please help me on this.

    Thanks in advance.

    Hello

    It makes no sense to do it in PL/SQL when you can do it with SQL.

    SQL is generally more efficient than PLSQL.

    And can you explain why you don't want to use analytical functions?

    This will update your table using a MERGE statement and an analytic function:

    MERGE INTO line_table lt
    USING
    (
       SELECT ROWID rid, header_value, row_number() OVER(PARTITION BY header_value ORDER BY ROWNUM) rn
         FROM line_table
    ) src
    ON (src.rid=lt.ROWID)
    WHEN MATCHED THEN
       UPDATE SET lt.line_number = src.rn;
    

    The result is less to:

    HEADER_VAL LINE_NUMBER

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

    ALAOF 1

    ALAOF 2

    ALAOF 3

    ALAOF 4

    ALAOF 5

    TRECYBEL 1

    TRECYBEL 2

    TRECYBEL 3

    TRECYBEL 4

    TRECYBEL 5

    TRECYBEL 6

    TRECYBEL 7

    Kind regards.

    Al

  • 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
    
  • How to get LASTDAY for each month between data dates...

    Hi friend

    I have a doubt, how to get LASTDAY for each month between data dates...

    for ex:
    My contribution will be like this
    date = 01/12/2011
    To date = 14/04/2011

    And I need an output like
    31/01/2011
    28/02/2011
    31/03/2011

    is it possible to achieve through sql query in oracle
    Thanks in advance for all friends to help him

    Hello

    Something like this (assuming that the dates are originally VARCHAR2s):

    SQL> var dt_start varchar2(10)
    SQL> var dt_end varchar2(10)
    SQL> exec :dt_start := '12-01-2011'
    
    PL/SQL procedure successfully completed
    
    SQL> exec :dt_end := '14-04-2011'
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> select last_day(
      2           add_months(
      3             trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM'),
      4             level-1
      5           )
      6         ) as result
      7  from dual
      8  connect by level <= months_between(to_date(:dt_end,'DD-MM-YYYY'), to_date(:dt_start,'DD-MM-YYYY'))
      9  ;
    
    RESULT
    -----------
    31/01/2011
    28/02/2011
    31/03/2011
     
    

    If the dates are already of the date data type, simply remove the to_date function.

  • need to generate unique sequence for each transaction number

    need to generate unique sequence for each transaction number

    Use sometihng like that



    use the orcl: sequence-next function val

  • 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

  • HOWTO generate a pulse for each Image Grabed?

    Hello

    I use a 7852DAQ card and a PCIe1429 framegrabber.

    In the momment I'm images grabing at 20 Hz with analog values PCIe1429 and measurement at 1 kHz with the 7852DAQ card.

    Now I would like to synchronize this measure two, I know what analog value is linked to my image.

    I think that the best way to get good timing is to generate a signal to each captured image. The best way of communication between the two cards should be triggering RTSI lines.

    With the IMAQ generate Pulse3 VI I was able to generate a continuous impulse signal a reading with DAQ card mit but this isn't what I want.

    Then I tried the Trigger IMAQ Drive2 VI.

    I did IMAQ Init and IMAQ create, IMAQ Grab Setup then the Trigger IMAQ Drive2 VI and then some time loop with IMAQ Grab acquire.

    My setup is Type of trigger "RTSI", number "0", trigger "Vertical sync Signal" drive and polarity of command high 'True '.

    My time loop has a 50ms in him waiting, so I should get a picture every 50ms and also get a pulse every 50ms. But this isn´t happenig. The pulses come about every second. When I use Trigger Drive 'Start Frame' I get the same behavior.

    So, what's the problem? I do not understand IMAQ Trigger Drive2 VI bad functionality?

    Thank you

    Hello Westgate,

    have you tried to use the player to trigger 'Start Frame' or 'Ongoing Acquisition' instead of 'vertical sync?

    In addition, you can check your FPGA code running on the R Series DAQ card: how you analyze the trigger in FPGA line, what is the interval of time to detect the pulse,...?

    Best regards
    Sebastian

  • ATTN: Staff [added kglad] double load for each month and one subscription

    Hello

    Each month I reveived TWO bills of adobe, but I only have ONE subscription in my account. I contacted the customer servive twice, but they both finally asked me to communicate with the Bank. However, the Bank asked me to contact adobe.

    I joined the subscription from August 12, 2016. When I finished first payment online, I have not received any confirmed e-mail. I tried to use photoshop, but it showed that I have a subscription. I thought I was suffering from network problem that the payment is not completed. Then I presented again. I received a confirmation by e-mail immediately. A month later, I found two charges of Adobe on the same date. I tried to do everything that I could to solve the problem, but the problem is still there... Can someone help me? And I hope that I can be reimbursed in double.

    Hello

    Please contact support by calling/chat for billing queries:

    Contact the customer service

    * Be sure to stay connected with your Adobe ID before accessing the link above *.

    You can also check the help below document:

    https://helpx.Adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

    Please go through the Adobe - General conditions of subscription as well.

    Kind regards

    Sheena

  • Mege of mail and e-mail pdf separated for each recipient?

    With Office 2010 - can I create mail merge using Word and Excel database doc to create PDF files and then send separate pdf personalized for each recipient in the list database?
    What version of Acrobat do I need? Is there a free trial?

    Thank you

    Yes, there is a free trial of Adobe Professional on Adobe's Web site. There are only two versions of Acrobat on Windows (Standard and Professional). On Mac, there are only of Acrobat Professional. The trial on the website is for Adobe Professional

  • Calc for the month that has data

    Hi - I have a calc below script, works, except that it fills for all months, but I want only the amount of change/fill when there is data in the months to "W1 - PR". I tried to say in my statement, if the amount is higher, then 0, then do the math, but miss me something, since it is still filling for all months.

    Accounts - Dense
    Periods of time - Dense
    Feature - sparse
    Types - sparse
    Years - sparse
    Scenario - sparse
    Versions - sparse


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    DIFFICULTY (FY09, estimate3, sandbox, A)
    "w1 - pr".
    (
    IF (@ISMBR (Estimate3) and @ISMBR("w1-pr") and @ISMBR ("sum Adeath") > 0)
    "Amount Depr'->"w1 - PR"= Jan->"license fees"-> NA_PT * Dec->"Amount Adeath"->"Split %. " 01;
    ENDIF
    )
    ENDFIX

    and @ISMBR ("sum Adeath") > 0

    Is not what you think it is. ISMBR returns true or false, not the value of data.

    try to use only

    and 'Adeath amount' > 0

  • Time series: finding max and min for each month

    Hello world. I'm working on a datasheet that has collected the data points for all day for the past 15 years.

    A column stores the date and column B contains a numeric value.

    I want to do the following:

    Create a new table (call it table #2) that:

    (1) is now a time series on a monthly basis (column A contains "year month"). This is why the table contains a header and 15 * 12 = 60 rows of data

    (2) B Col contains the Max value of this month.

    (3) C Col contains the value this month min

    Table #2 should be calculated automatically because I need to find these values for several series. Any ideas?

    Here is a way that I came up with

    In the table above, your original data is in columns B and C.

    I've added three additional columns (A, D and E):

    D2 = Year (B2) & NUMTOBASE (MONTH (B2), 10, 2)

    It's shorthand dethrone select D2, and type (or copy and paste it here) the formula:

    = Year (B2) & NUMTOBASE (MONTH (B2), 10, 2)

    E2 = IF (D1≠D2, 0, E1 + 1).

    Select copy of D2 to E2,

    Select cells D2 at the end of column E, block

    A2 = D2 & NUMTOBASE (E2, 10, 2)

    Select A2, copy

    Select A2 at the end of the A2 column, paste

    now create a second table summary as shown:

    For 'Summary Table 2016:

    the first four lines are the lines of header

    There are 35 total lines

    Enter the year in cell B1

    A5 = −4 LINE)

    B5 = SIERREUR (VLOOKUP ($B$ 1 & NUMTOBASE(B$4,10,2) & NUMTOBASE($A5,10,2), data: $A:$ C, 3, 0), "")

    Select cell B5, copy

    Select cells B5 at the end of row 5, dough

    Select A5 thru M5, copy

    Select cell A5 at the end of the M column, paste

    B2 = MIN (B)

    B3 = MAX (B)

    Select the cells B2 to B2, copy

    Select the cells B2 through M3, dough

    now duplicate the table and change the year to 2015 for the next year.

    You can duplicate this table as necessary to summarize a year

Maybe you are looking for