Min date for each month from list

Hi all,
I need to select only minimal date for each month from this sample 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 So the result should be:
04.01.2011
01.02.2011
03.10.2011How do I perform 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

Similar Messages

  • MDX to dynamically create period to date for each month of current year

    I need some help with MDX. I am not even sure if this is possible to do but here is what I need.  Any help is greatly appreciated.
    I have a Date dimension with a hierarchy defined as Year-Qtr-Month-Date
    I have a measure called Rentals
    Assume the current date is 10/24/2014.  I want to display by month for the year 2014, the sum of rentals equivalent to the current MTD.  So January would sum 1/1 thru 1/24.  February would sum 2/1 thru 2/24.  March would sum 3/1 thru
    3/24, etc.
    On the end of the current month, all months would display the sum of the whole month. I am not concerned if a month ends on the 30th or 31st.  The end is end.
    It needs to be dynamic enough so that if the current date is the 27th, each month would sum from the 1st to the 27th.

    Hi Rocko,
    According to your description, you want to compare the sum amount of rentals for each month, right?
    In MDX, we can use
    PARALLELPERIOD function returns a member from a prior period in the same relative position as a specified member. So you can use the query like
    with set Period as {[Arrival Date].[Date].[Month].&[2014]&[1]:[Arrival Date].[Date].[Month].&[2014]&[27]}
    member [Arrival Date].[Date].[0] as sum({Period})
    member [Total Amount N-1] as (PARALLELPERIOD([Arrival Date].[Date].[Month], 1, [Arrival Date].[Date].[Year].&[11]), [Measures].[Total Amount])
    Here is a sample query on AdventureWorks cube.
    SELECT ParallelPeriod ([Date].[Calendar].[Calendar Semester]
    , 3
    , [Date].[Calendar].[Month].[October 2003])
    ON 0
    FROM [Adventure Works]
    Regads,
    Charlie Liao
    TechNet Community Support

  • Cummulative last 3 months of each month from Calmonth Interval variable

    Hi,
      we have one complex scenario where we have to display dispatch quantity against the Calendar Month (user input variable).
    for example if user enters; FROM:  january 2009  TO:  march 2009, the dispatch quantity should be calculated as cummulative of last 3 months of each month as follows;
    (jan 2009Dec 2008Nov 2008)(Feb 2009Jan 2009Dec 2008)(Ma 2009feb 2009jan 2009)
    the same way we need calculate cummulative last 24 & 36 months for each month from user entry.
    Thanks,
    Janapati N

    Hi,
    Thanks for you replay and documentation, but it doesn't give me excatly the functionality I'm after. The only MTD calculation code the document provides is the calculation of the following functionality:
    "Month to Date (MTD) u2013 From the 1st of month to u201CKey Dateu201D - for current year." This doesn't give the the functionality I want, which is to retrieve a given vaule for a Key Figure for the last dates of the months in a year to calculate MTD and YTD.
    This way I have created the query is to have multiple hidden Key Figures that calculates the MTD and YTD.
    In Columns in Query Designer it will look something like this:
    Selection: MTD January--> Date = 31.01.2008, Key Figure (Always Show)
    Selection: YTD January --> Date= 31.01.2008, Key Figure (Always Show)
    Selection: MTD February --> Date= 29.02.2008, Key Figure (Always Hide)
    Formula: MTD February --> MTD February - MTD January (Always Show)
    Selection YTD February --> Date = 29.02.2008, Key Figure (Always Show)
    And so on....
    This is off course a simplified version, but it shows the core of the solution. What I want to achive here is that the dates used to get the Key Figures (last date of a month) is calculated as flexible as possible, so that the users can go back and forth in time without worrying about the leap year problem and so on. I have now used an offset from the last date of last year and this is good for all the normal years, but when it is a leap year the query will use wrong dates to get the key figure vaule for the last date of each month.
    Any ideas on how to achieve this without creating 12 different Customer Exit variables (one for each end date of each month)?
    Thanks
    Regards
    Oddmar Lid

  • How to apply Date condition for each month in 12 month period to my SQL query

    I am trying to retrieve all Outstanding Problem tickets in my Trendline SSRS report.
    I need to pull the OpenDate <= Last day of last month And CloseDate >= 1st day of current month
    for each month in the Last 12 months. How do I accomplish this in my query?
    I must also need to pull the oustanding tickets for the next 11 months in the same query
    where it will automatically pull the outstanding tickets for when a new month comes
    in out of the 12 month period?
    Here's a sample of my query to pull July 2013 Outstanding Problem tickets:
    Select OpenDate, CloseDate, Ref_Num, Type, status
    From Call_Req
    Where OpenDate <= '2013-07-31 00:00:00' And CloseDate >= '2013-08-01 00:00:00'
    And Type = 'P'
    My Results:
    OpenDate
    CloseDate
    Ref_Num
    Type
    status
    6/13/2013 7:41
    8/26/2013 12:41
    P1726456FY13
    P
    CL
    6/13/2013 8:17
    8/23/2013 12:31
    P1726612FY13
    P
    CL
    6/13/2013 10:17
    9/6/2013 16:54
    P1727352FY13
    P
    CL
    7/12/2013 10:46
    9/6/2013 10:23
    P1812568FY13
    P
    CL
    7/18/2013 10:17
    9/6/2013 8:53
    P1830452FY13
    P
    CL
    7/29/2013 15:54
    9/6/2013 16:16
    P1862906FY13
    P
    CL
    5/17/2013 20:51
    8/22/2013 9:09
    P1653380FY13
    P
    CL
    5/30/2013 13:29
    8/26/2013 7:33
    P1685693FY13
    P
    CL
    7/15/2013 14:14
    9/7/2013 9:42
    P1818874FY13
    P
    CL
    6/7/2013 15:49
    9/6/2013 16:46
    P1712265FY13
    P
    CL
    7/18/2013 10:25
    9/7/2013 9:18
    P1830516FY13
    P
    CL
    7/24/2013 16:30
    8/12/2013 18:26
    P1849909FY13
    P
    CL
    Talitha Davis

    Would this Work?
    DECLARE @now DATE = GETDATE();
    WITH months(lvl, daydate)
    AS (
    SELECT
    1,
    @now
    UNION ALL
    SELECT
    lvl + 1,
    DATEADD(MONTH, -1, daydate)
    FROM months
    WHERE lvl < 12
    ), dateranges(period, opendate, closedate)
    AS (
    SELECT
    CAST(YEAR(daydate) AS CHAR(4))
    + '-'
    + RIGHT('0' + CAST(MONTH(daydate) AS varCHAR(2)), 2),
    DATEADD(DAY, 0-DAY(daydate), daydate),
    DATEADD(DAY, 1-DAY(daydate), daydate)
    FROM months
    SELECT
    b.period,
    a.OpenDate,
    a.CloseDate,
    a.Ref_Num,
    a.Type,
    a.status
    From Call_Req a
    INNER JOIN dateranges b
    ON
    a.OpenDate <= b.opendate
    AND
    a.CloseDate >= b.closedate
    WHERE Type = 'P';
    Microsoft Certified Trainer & MVP on SQL Server
    Please "Propose as Answer" if you got an answer on your question, and vote for it as helpful to help other user's find a solution on a similar question quicker.

  • Have family plan with 250 data which I almost use each month.  Going on vacation and will be on the road for two weeks.  Should I up my data for a month then change back.  Is it worth it or should I just run over and pay the extra 15 per gig?

    have family plan with 250 data which I almost use each month.  Going on vacation and will be on the road for two weeks.  Should I up my data for a month then change back.  Is it worth it or should I just run over and pay the extra 15 per gig?

    Hello mlazaretti. Vacation time is awesome. (Especially a road trip!) Since you will be going out for two weeks, you never know if having extra data may come in handy. I highly recommend switching to the next tier up so this way you have more data. This way it is only $10.00 more versus $15.00, and you dont have to worry about overages. Then change back at the start of the next billing cycle.
    If you need help making this change let us know! Have a safe trip!
    NicandroN_VZW
    Follow us on twitter @VZWSupport

  • How can I create a matrix question? Specifically, I need a question in table format that allows each respondent to list a number of events and then data for each event (date, location, number of participants, topics covered, etc.

    How can I create a matrix question? Specifically, I need a question in table format that allows each respondent to list a number of events and then data for each event (date, location, number of participants, topics covered, etc.

    Hi,
    Sorry, we do not support a matrix-question field.   Please try the multilines text field (where your participant can enter multiple lines in the input text box) and see if it works for you.
    Thanks,
    Lucia

  • How to Get Missing Dates for Each Support Ticket In My Query?

    Hello -
    I'm really baffled as to how to get missing dates for each support ticket in my query.  I did a search for this and found several CTE's however they only provide ways to find missing dates in a date table rather than missing dates for another column
    in a table.  Let me explain a bit further here -
    I have a query which has a list of support tickets for the month of January.  Each support ticket is supposed to be updated daily by a support rep, however that isn't happening so the business wants to know for each ticket which dates have NOT been
    updated.  So, for example, I might have support ticket 44BS which was updated on 2014-01-01, 2014-01-05, 2014-01-07.  Each time the ticket is updated a new row is inserted into the table.  I need a query which will return the missing dates per
    each support ticket.
    I should also add that I DO NOT have any sort of admin nor write permissions to the database...none at all.  My team has tried and they won't give 'em.   So proposing a function or storable solution will not work.  I'm stuck with doing everything
    in a query.
    I'll try and provide some sample data as an example -
    CREATE TABLE #Tickets
    TicketNo VARCHAR(4)
    ,DateUpdated DATE
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-01')
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-05')
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-07')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-03')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-09')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-11')
    So for ticket 44BS, I need to return the missing dates between January 1st and January 5th, again between January 5th and January 7th.  A set-based solution would be best.
    I'm sure this is easier than i'm making it.  However, after playing around for a couple of hours my head hurts and I need sleep.  If anyone can help, you'd be a job-saver :)
    Thanks!!

    CREATE TABLE #Tickets (
    TicketNo VARCHAR(4)
    ,DateUpdated DATETIME
    GO
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-01'
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-05'
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-07'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-03'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-09'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-11'
    GO
    GO
    SELECT *
    FROM #Tickets
    GO
    GO
    CREATE TABLE #tempDist (
    NRow INT
    ,TicketNo VARCHAR(4)
    ,MinDate DATETIME
    ,MaxDate DATETIME
    GO
    CREATE TABLE #tempUnUserdDate (
    TicketNo VARCHAR(4)
    ,MissDate DATETIME
    GO
    INSERT INTO #tempDist
    SELECT Row_Number() OVER (
    ORDER BY TicketNo
    ) AS NROw
    ,TicketNo
    ,Min(DateUpdated) AS MinDate
    ,MAx(DateUpdated) AS MaxDate
    FROM #Tickets
    GROUP BY TicketNo
    SELECT *
    FROM #tempDist
    GO
    -- Get the number of rows in the looping table
    DECLARE @RowCount INT
    SET @RowCount = (
    SELECT COUNT(TicketNo)
    FROM #tempDist
    -- Declare an iterator
    DECLARE @I INT
    -- Initialize the iterator
    SET @I = 1
    -- Loop through the rows of a table @myTable
    WHILE (@I <= @RowCount)
    BEGIN
    --  Declare variables to hold the data which we get after looping each record
    DECLARE @MyDate DATETIME
    DECLARE @TicketNo VARCHAR(50)
    ,@MinDate DATETIME
    ,@MaxDate DATETIME
    -- Get the data from table and set to variables
    SELECT @TicketNo = TicketNo
    ,@MinDate = MinDate
    ,@MaxDate = MaxDate
    FROM #tempDist
    WHERE NRow = @I
    SET @MyDate = @MinDate
    WHILE @MaxDate > @MyDate
    BEGIN
    IF NOT EXISTS (
    SELECT *
    FROM #Tickets
    WHERE TicketNo = @TicketNo
    AND DateUpdated = @MyDate
    BEGIN
    INSERT INTO #tempUnUserdDate
    VALUES (
    @TicketNo
    ,@MyDate
    END
    SET @MyDate = dateadd(d, 1, @MyDate)
    END
    SET @I = @I + 1
    END
    GO
    SELECT *
    FROM #tempUnUserdDate
    GO
    GO
    DROP TABLE #tickets
    GO
    DROP TABLE #tempDist
    GO
    DROP TABLE #tempUnUserdDate
    Thanks, 
    Shridhar J Joshi 
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Last Entry Date for Each Quarter

    Hi,
    I want to find out the last entry date for each quarter. The query I am using is this:
    SELECT 
    Country.Name as Country,
    CONVERT(DATE,MAX([CreationDate])) as LastDateOfClipEntry,
    DATEPART(Year,([CreationDate])) as Year,
    DATEPART(Quarter,([CreationDate])) as Quarter
    FROM 
    [dbo].[Clip]
    JOIN Office on Office.Code = Clip.Office
    JOIN Country on Country.Code = Office.Country
    WHERE YEAR(CreationDate) IN (@YEAR)
    GROUP BY Country.Name,DATEPART(Year,([CreationDate])) ,DATEPART(Quarter,([CreationDate]))
    ORDER BY Country.Name
    Now based on the column group I added in my report the result is coming correct but not properly formatted as I want.
    Below is the snapshot how its coming now:
    I don't want the extra blanks coming for each occurrence. There should be only one line for Australia and in the single line it should show the last entry date for that quarter. How can I achieve that ? Below is the snapshot showing current config:
    Thanks a lot in advance. Any help would be appreciated.
    Vivek Kamath

    Hi Vik2907,
    According to your description, you have a matrix which shows you those unexpected cells. Right?
    In this scenario, the reason caused this problem is the group setting. Mostly, you set the row group on a wrong field. As we tested in our local environment, if you set the row group on LastDateOfClipEntry, it will render the data as the screenshot you post.
    Please check both Row and Column Group setting, make sure they are group on proper field.
    Reference:
    Tables, Matrices, and Lists (Report Builder and SSRS)
    Understanding Groups (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How to do "for each month in 2008 sum amount where category is cash"

    The table format is:
    Date(MM/DD/YYYY) Amount Description Category Account
    01.02.2008 -21000 benzina (C) Calatorii Cash
    01.04.2008 -2000 Mancare (C) Calatorii Cash
    01.05.2008 -2000 Mancare (C) Comisioane Cash
    05.12.2008 4706 diverse (C) Comisioane BT - Mondo
    08/25/2008 8807 diverse (C) Calatorii BRD - PFA
    08/25/2008 104000 diverse (C) Comisioane BRD - Multiplan
    10.10.2008 6385849 diverse (C) Comisioane BRD - Atucont
    10/26/2008 943699 diverse (C) Calatorii BRD - ISIC
    10/27/2008 95313 diverse (C) Comisioane Cash
    10/28/2008 -300 Comisioane (C) Comisioane BRD - ISIC
    I am trying to do the following:
    for each month in 2008
    sum (Amount) where Category is (C) Calatorii
    =>
    January -23000
    February 0
    for each month in 2009 up until now
    sum (Amount) where Category is Cash
    =>
    January 35000
    With these 2 samples I can manage the other functions I need.
    Thanks in advance.

    Question asked and responded several times.
    In column H of the first table I inserted the formula:
    =YEAR(B)*100+MONTH(B)
    In column B of the second table, the formula is:
    =SUMIFS(Tableau 1 :: C,Tableau 1 :: G,"=Cash",Tableau 1 :: H,"="&A)
    CAUTION
    I don't know your system settings.
    If your system uses the decimal comma, you will have to use:
    =SUMIFS(Tableau 1 :: C;Tableau 1 :: G;"=Cash";Tableau 1 :: H;"="&A)
    Yvan KOENIG (from FRANCE jeudi 23 avril 2009 15:04:49)

  • Problem to calculate the coherence (using NetworkFunction-VI) with only 1 row of data for each, the stimulus and response input

    Hello,
    I am trying to calculate the coherence of a stimulus and response
    signal using the Network Functions (avg) VI's. The problem is that I
    always get a coherence of "1" at all frequencies. This problem is
    already known (see KnowledgeBase document: Why is the Network Functions (avg) VI's Coherence Function Output "1"?).
    My trouble is that the described solution (-> the stimulus and response input matrices need to have at least two rows to get non-unity coherence values) doesn't help me much, because I only have one array of stimulus data and one array of response values.
    Thus, how can I fullfil the 'coherence-criteria' to input at least two rows of data each when I just have one row of data each?
    Any hint or idea is very much appreciated. Thanks!
    Horst

    With this weird board layout, I'm not sure whether you were asking me, but, on the assumption that you were, here goes:
    I found no need to use the cross-power spectrum and power spectrum blocks
    1... I was looking for speed.
    2... I already had the component spectral data there, for other purposes. From that, it's nothing but addition and multiplication.
    3... The "easy" VIs, assume a time wave input, as I recall. Which means they would take the same spectrum of the same timewave several times, where I only do it once.
    I have attached PNGs of my code.
    The PROCESS CHANNEL vi accepts the time wave and:
    1... Removes DC value.
    2... Integrates (optional, used for certain sensors).
    3... Windows (Hanning, etc. - optional)
    4... Finds spectrum.
    5... Removes spectral mirrors.
    6... Scales into Eng. units.
    7... From there, you COULD use COMPLEX-TO-POLAR, but I don't care about the phase data, and I need the MAG^2 data anyway, so I rolled my own COMPLEX-TO-MAG code.
    The above is done on each channel. The PROCESS DATA vi calls the above with data for each channel. The 1st channel in the list is required to be the reference (stimulus) channel.
    After looping over each channel, we have the Sxx, Syy, and Sxy terms. This code contains some averaging and peak-picking stuff that's not relevant.
    From there, it's straightforward to ger XFER = Sxy/Sxx and COHERENCE = |Sxy|^2 / (Sxx * Syy)
    Note that it uses the MAGNITUDE SQUARED of Sxy. Again, if you use the "easy" stuff, it will do a square-root operation that you just have to reverse - it is obtained faster by the sum of the squares of the real and imag parts.
    Hope this helps.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    ProcessChannel.png ‏25 KB

  • Trouble summing expenses for each month

    I use a website to track my expenses and it exports to csv. I plan on building some graphs based on that csv.
    The csv format is:
    Date(MM/DD/YYYY),Amount,Description,Category,Account,Jived,
    01/02/2008,-210.00,"benzina",(C) Calatorii,Cash,yes,
    4/4/2009 ...
    I am trying to do the following:
    1) do the following algorithm:
    for each month in 2008
    sum (Amount) where Category is Cash
    for each month in 2009 up until now
    sum (Amount) where Category is Cash
    fill NEWTABLE with rows where description matches Calatorii AND matches somethingelse
    2) use numbers to autoupdate the graphs' value from the csv file instead of importing it as a table every time I need to update
    I am new to Numbers but I think that with these samples I'll manage to design my graphics.

    Answer found here: http://discussions.apple.com/thread.jspa?threadID=1985495&tstart=0 It seems starting a similar thread in Numbers 2009 was more useful than staying within the proper category.

  • Different BOM for each month

    Hi,
    The BOM is different for each month. If i make different alternatives for each month and run the LTP will it help to get the raw material requirement as per the BOM for that month. Example BOM for NOV/DEC will be not same but we want to estimate the raw material req for next year.
    Kindly advise what i need to do?
    Regards
    ShankarR

    Dear Shankar,
    1.What is the business contraint in using change number functionality to address this requirement without creating any
    additional alternative BOM?
    2.Say you create the first alternative BOM using a change number and save all the BOM components.
    3.The default valid from date will be the valid from date of the change number and valid to date will be 31.12.9999.
    4.Whenever there is a BOM change use a different change number with valid from date say 25.10.2010,so using this in the
    same BOM delete the components and add the new component's or make any BOM change and save.
    5.For the deleted components the valid from date will be say (you have created using today's date for BOM creation)
    05.10.2010 and the valid to date will be 25.10.2010.
    6.What is the advantage of creating new alternative BOM?
    6.How are you using the LTP results for inventory purpose,say how are you planning the raw material's requirement for the
    next year based on this year's BOM?
    7.LTP is not only the feasibility of material procurement,but also production that can be produced with available resource.
    Check and revert
    Regards
    S Mangalraj

  • Query to count ACTIVE records for each month

    All,
    I have a requirement to count the number of active customers for each month of an year. Let's say, we have 3 fields in the table:
    ID               ActiveStart             ActiveEnd
    1                 1/1/2014               11/30/2014
    In this scenario, the member with ID was active for all the months (Jan-November) EXCEPT, December. So, the result set I am expecting for the Month of January to December is like below:
    Month       CountOfMembers
    Jan            1
    Feb           1
    Mar           1
    April          1
    May           1
    June          1
    July           1
    August      1
    Sept          1
    Oct            1
    Nov           1
    Dec           0 (Since, the member was NOT active in this month)
    Similarly, if you have another member whose start date is 1/1/2014 and termination is '5/31/2014', then, I would need to add 1 for months of January till May, the member WON'T be counted for the rest of the months. So, in this case, the count will be come
    "2" for months January till May, it will remain "1" for June till November and still "O" for December.

    >>I have a requirement to count the number of active customers for each month of an year. Let's say, we have 3 fields [sic: columns are not fields] in the table [sic: tables have names]: <<
    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI-ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need to
    know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI-ISO Standard SQL. And you need to read and download the PDF for: 
    https:--www.simple-talk.com-books-sql-books-119-sql-code-smells-
    There is no magical universal “id” in RDBMS, tables have names and columns have constraints and types. Most of the work in SQL is done in the DDL. Here is a possible schema. 
    CREATE TABLE Duty_Roster
    (member_nbr INTEGER NOT NULL PRIMARY KEY,
     duty_start_date DATE NOT NULL,
     duty_end_date DATE NOT NULL,
    CHECK (duty_start_date <= duty_end_date),
    INSERT INTO Duty_Roster
    VALUES 
    (1, '2014-01-01', '2014-11-30'),
    (2, '2014-01-01', '2014-05-31');              
    >> In this scenario, the member with ID was active for all the months (Jan-November) EXCEPT, December. So, the result set I am expecting for the Month of January to December is like below: <<
    A month is a temporal measurement that makes no sense without a year. But if you knew the ISO temporal model, you would see that you have what is called an INTERVAL data type. T-SQL does not support it yet. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Month_Periods
    (month_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (month_name LIKE  '[12][0-9][0-9][0-9]-[01][0-9]-00'),
     month_start_date DATE NOT NULL,
     month_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (month_start_date <= month_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    SELECT M.month_name, COUNT(R.member_nbr) AS member_cnt
      FROM Month_Periods AS M,
           Duty_Roster AS R
     WHERE M.month_start_date 
           BETWEEN R.duty_start_date AND R.duty_end_date
       AND M.month_end_date 
           BETWEEN R.duty_start_date AND R.duty_end_date;
    We had no business rules about partial months, so I guessed. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Query to find data of each month

    hi,
    i have 2 table.
    1) Order_tb
    Name Null? Type
    ORDERID NOT NULL NUMBER
    CUSTOMERID NUMBER
    ORDERDATE DATE
    2) Order_d
    Name Null? Type
    ORDERID NUMBER
    PRODUCTID NOT NULL NUMBER
    PRODUCTNAME VARCHAR2(20)
    SELLINGPRICE NUMBER
    i need to find the total find the total selling price for each month in the year 2012 (orderdate).
    i have tried using join, but i could not take the data of 2012 particularly. Please help me on this issue.
    thank you
    Edited by: RSD on Feb 28, 2013 9:18 AM

    Hi,
    RSD wrote:
    ... i have tried using join, but i could not take the data of 2012 particularly. Please help me on this issue.The WHERE clause below is what limits the results to 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 this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Simplify the problem. For example, pretend you're only interested in the first 3 or 4 months of 2012; we'll find a solution tht can easily be adapted for 12 (or any other number) of motnhs.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Calculate total empoyee days (as of present) that have elapsed for each month in a FY

    Hello, everyone,
    I'm running CF server connecting to an Oracle (11g)  db.
    I have a table that keeps track of projects (past, present, future) and need a way to sum the days for each project, for each month, that have happened.
    For example.
    ID   -
    Name         
    -   Start
    -   Stop 
    - Employees
    001
    Project A     
    01-Oct-14
    31-Dec-14      
    8
    002
    Project B     
    06-Feb-15
    21-Feb-15      
    9
    003
    Project C     
    30-Oct-14
    29-Nov-14      
    3
    004
    Project D     
    26-Dec-14
    16-Apr-15     
    21
    I'm trying to create an overview where the display will have the months of a Fiscal Year go across the page, indicating the number of employee days for each project that have elapsed. (NOT counting the current day).  New requirement: To make matters even more complex, there is a related table for the employees showing what dates they actually started and stopped (not every employee starts on day 1 and ends on the last day.. some start a day or two after the project start, etc.)
    I'm not wrapping my head around this, for some reason. Mental block. Any ideas?
    Someone in another forum suggested a PIVOT.  That's above my paygrade (I have never used PIVOT, don't understand how it works, etc.)
    V/r,
    ^_^

    This may be a good start. Display by Month Year the Average and Sum Dates between Start and Stop by Project.
    SELECT      CAST    (
            (CAST(MONTH(Start) AS varchar(2)) + '/01/' + CAST(YEAR(Start) AS varchar(4)))
            AS DateTime
        AS DatePeriod,
        AVG(DateDiff(day, Start, Stop)) AS AverageDaysToClose,
        SUM(DateDiff(day, Start, Stop)) AS SumTotalDaysToClose,
        Name
    FROM     Projects
    GROUP BY CAST    (
            (CAST(MONTH(Start) AS varchar(2)) + '/01/' + CAST(YEAR(Start) AS varchar(4)))
            AS DateTime
        Name
    ORDER BY DatePeriod, Name

Maybe you are looking for

  • Using NI-VISA to detect USB insertion/​removal

    Is there a way to use NI-VISA to detect when a USB device has been inserted or removed? I am currently using Windows API in my LabWindows application to capture the WM_DEVICECHANGE event.  When this event is called, I check to see if the USB devices

  • LiveUpdate 6-not running after last update

    application not running after start win7x64, but I did not set anything and not even start pls. test application main PC: moth. H97 CPU: Corei-5 VGA: GTX 560Ti thx

  • Ipad exchange calendar issues.

    Afternoon all. I'm having some trouble with the Exchange calendar on both my iPad Air and iPhone 5S. I Can create calendar entries and invite attendees no problem. the issue comes when those attendees accept or decline the invitation. I receive an em

  • Export to Excel - currency problem

    Post Author: bontempi CA Forum: Exporting I'm using Crystal Reports 8.5 with Visual Basic 6.  If I export to Excel using either the built in button on the report viewer toolbar, or using the Export function then any £ symbols are changed to $ symbols

  • Export Data Sets as jpgs?

    Is there a way to export data sets as jpgs instead of psd? The whole point is fast file creation and having a folder full of new psds which I then have to convert to jpg is kinda a silly step. Am I missing something?