Need counts of payment amounts per week grouped by week

  • Hello,

    I have a code that suppose to give me weekly(summed) payments, but instead, it gives me random points, not (1*7, 2*7,...)

    I suspect it maybe because it doesn't include the zeros, but i couldn't figure out how to fix it

    Note: I use MySQL 5.1.41, so please give compliance code


     

  • This was removed by the editor as SPAM

  • can you explain more ?

    thanks for your reply

  • This was removed by the editor as SPAM

  • joewhite wrote:

    Hello,

    I have a code that suppose to give me weekly(summed) payments, but instead, it gives me random points, not (1*7, 2*7,...)

    I suspect it maybe because it doesn't include the zeros, but i couldn't figure out how to fix it

    Note: I use MySQL 5.1.41, so please give compliance code

    You have not provided anything to go on to help you.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This was removed by the editor as SPAM

  • Campbell156 wrote:

    SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],
    COUNT(*) AS Count
    FROM dbo.your_table_name
    GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])

     

    Welcome aboard!  That's a great bit of code considering the OP offered almost no details.

    It does seem to assume that weeks start on Mondays (which I totally agree with and is ISO).  We'll see how the OP defines what a week is.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden wrote:

    Campbell156 wrote:

    SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],
    COUNT(*) AS Count
    FROM dbo.your_table_name
    GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])

    Welcome aboard!  That's a great bit of code considering the OP offered almost no details.

    It does seem to assume that weeks start on Mondays (which I totally agree with and is ISO).  We'll see how the OP defines what a week is.

    Not so sure about that.  I live in the middle east and here the week starts at Sunday.  I think that this would also be the case at most Muslim countries since for Muslims Friday is  the holy day so the weekend starts at Friday and not at Saturday.  In any case I  agree with you that the original poster should have write more details.

    Adi

  • Adi Cohn wrote:

    Jeff Moden wrote:

    Campbell156 wrote:

    SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],

    COUNT(*) AS Count

    FROM dbo.your_table_name

    GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])

    Welcome aboard!  That's a great bit of code considering the OP offered almost no details.

    It does seem to assume that weeks start on Mondays (which I totally agree with and is ISO).  We'll see how the OP defines what a week is.

    Not so sure about that.  I live in the middle east and here the week starts at Sunday.  I think that this would also be the case at most Muslim countries since for Muslims Friday is  the holy day so the weekend starts at Friday and not at Saturday.  In any case I  agree with you that the original poster should have write more details.

    Adi

    A lot of companies here in the US do the same thing (week starts on Sunday).  Even SQL Server defaults to Sunday start dates.  I'm also familiar with the Muslim calendar you mention an other calendars such as the first day of the week being Thursday.

    Just to be sure, none of the reasons I have for agreeing with Monday start dates have a thing to do with religion.  Like I said, one of the reasons is that it's ISO compliant.  The other reasons are mostly for computational convenience... 01 Jan 1900 and 01 Jan 1753 both occurred on Mondays.

    Heh... I also like the fact that "the weekend" consists of two days that start with the same letter as some of my goals for weekends... simple, safe, stress-free, salubrious, satisfying, solitude. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply