• yvesql (10/21/2016)


    Hi, suppose i have the following table, is it possible to group the totals by week nr? (from Monday to Sunday)

    date/time amount1amount2

    1/05/2016 12:0011

    2/05/2016 12:0021

    3/05/2016 12:0041

    3/05/2016 12:0061

    3/05/2016 12:0082

    3/05/2016 12:03101

    5/05/2016 12:001221

    8/05/2016 12:00141

    8/05/2016 12:30161

    10/05/2016 12:00184

    11/05/2016 14:00204

    12/05/2016 12:00224

    13/05/2016 12:00244

    14/05/2016 12:00264

    15/05/2016 12:00284

    16/05/2016 12:00304

    17/05/2016 12:00324

    18/05/2016 12:00344

    19/05/2016 12:00364

    This is what i want:

    week sum(Amount1) sum(Amount2)

    Week1711

    Week187229

    Week1913824

    Week2013216

    see attachment

    The 1st of January, 2016, occurred on a Friday. What is your definition of what "Week 1" of any given year? If it's ISO Weeks, then piece o' cake. If it's SQL Server Weeks, then not so good because those don't always have 7 days in them. Sergiy's comes the closest to being correct, especially since he also identified that you haven't defined what "Week 1" of any given year is.

    Again, what is your definition of what "Week 1" of any given year?

    Also, please see the first link in my signature line below for future posts. It'll help you get responses to your posts a whole lot faster.

    --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)