How to get weekly and Monthly view from daily in sql server

  • Hello All,

    I have a table like below.

    I need to get daily,weekly and monthly calls data from this.

    My out put would be like below

    Could any one please help what is the query to write here

     

     

    Attachments:
    You must be logged in to view attached files.
  • Please provide DDL (table definitions) & sample data as insert scripts as described in How to post code problems.

     

  • So please explain how the 1/1/2021 entry for sales of 100 gets knocked down to only 5 calls in the desired output.

    To @ratbak's point about providing DDL, please see the article at the first link in my signature line below.

    --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)
    Intro to Tally Tables and Functions

  • What reporting tool are you using? How's your data structured?

    If you're querying against a data warehouse, I'd probably use Excel, because it provides a relatively simple UI. you can use PowerBI too... The only downside is that to do complex stuff, you have to learn DAX.

  • This can all be done in T-SQL pretty easily... we just need so reasonable data and task description to work with.

    --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)
    Intro to Tally Tables and Functions

Viewing 5 posts - 1 through 5 (of 5 total)

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