This discussion is archived
4 Replies Latest reply: Nov 11, 2013 8:09 AM by rp0428 RSS

query for getting data for every quarter for financial year

lakmesri Newbie
Currently Being Moderated

Hi,

My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.

For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.

In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..

Thanks in advance.

  • 1. Re: query for getting data for every quarter for financial year
    Nikolay Savvinov Guru
    Currently Being Moderated

    Hi,

     

    Oracle supports quarters in date format, e.g.:

     

    select to_char(sysdate, 'Q') from dual;

     

    Best regards,

      Nikolay

  • 2. Re: query for getting data for every quarter for financial year
    lakmesri Newbie
    Currently Being Moderated

    Yes, that I agreed. But I want the logic of getting quarters for financial year.

  • 3. Re: query for getting data for every quarter for financial year
    Nicolas.Gasparotto Oracle ACE
    Currently Being Moderated

    lakmesri wrote:

     

    Hi,

    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.

    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.

    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..

    Thanks in advance.

    How can you get 8 quarters within a year ? I'b be concerned here.

    lakmesri wrote:

     

    Hi,

    ...

    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..

    Thanks in advance.

    First, that question is really not clearly asked. Second how could it be urgent ? You even did not tell us your Oracle version, did not show any tables descr, output sample nor any effort on your side to work on.

     

    Nicolas.

  • 4. Re: query for getting data for every quarter for financial year
    rp0428 Guru
    Currently Being Moderated
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.

    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.

    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..

    Nothing is 'urgent' on the forums. If you have an urgent problem you need to hire a consultant.

     

    A simple query with a WHERE clause that specifies the MIN and MAX date will 'get the data for every quarter'

    SELECT col1, col2, col3 from myTable WHERE myColumnDate BETWEEN myFirstDesiredDate and myLastDesiredDate

    If 'for every quarter' means you want data grouped by quarter then you have to provide some sample data (in the form of INSERT statements) and show what the results should look like.

     

    The sample query provided will identify quarters for you since 'your' quarters have the same months as 'calendar' quarters.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points