Results 1 to 4 of 4

Thread: Months query

  1. #1
    Join Date
    Mar 2006
    Posts
    42

    Unanswered: Months query

    On the basis of my query i have built a totals query as follows:
    SELECT Sum(qryMargin.MarginInvoice) AS SumOfMarginInvoice, qryMargin.invoicedate
    FROM qryMargin
    GROUP BY qryMargin.invoicedate;

    I want to break down the sum so obtained into months on the basis of the invoicedateand also to arrange them to be not in
    alphabetical order but following the order of the months, e.g. january,february,march etc
    Can you help me ?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    SELECT Sum(qryMargin.MarginInvoice) AS SumOfMarginInvoice, month(qryMargin.invoicedate)
    FROM qryMargin
    GROUP BY month(qryMargin.invoicedate);
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Remember, that if you group by month that February 2006 will also be lumped with February 2007
    George
    Home | Blog

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    then peljo shoulda said "by month and year"

    maybe i'm getting old, or maybe i've answered too many questions, and i'm tired of answering questions that weren't asked, or giving a suggestion that turns out to have been unnecessary

    like for instance, lumping all months together over as large a number of years as possible is sometimes exactly what you want to do

    for example, to compute stats on annual rainfall by month

    oh, sorry, MarginInvoice by month

    alternatively, perhaps there's another reason i didn't jump immediately to suggest grouping by month and year (like PHV did)

    although, to be fair to both of you, your suggestion is probably correct 93.7% of the time



    no, perhaps i grouped by exactly what was asked, so that peljo would discover what you just mentioned

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •