Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4272812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:37:41+00:00 2026-05-21T07:37:41+00:00

Need to build a query showing how much customers spend money per week, month,

  • 0

Need to build a query showing how much customers spend money per week, month, quarter, 6 months and a year on a daily on-line game. There is a field create date(datetime) field when one customer enters the game.

Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:37:42+00:00Added an answer on May 21, 2026 at 7:37 am

    Perhaps something like this.

    declare @T table (CreatedDate datetime, MoneySpent int)
    
    insert into @T values
    ('20101231', 5),
    ('20100101', 10),
    ('20100102', 20),
    ('20100103', 30),
    ('20110104', 40),
    ('20110105', 50),
    ('20110106', 60),
    ('20110107', 70)
    
    -- per year
    select
      sum(MoneySpent) Spent,
      year(CreatedDate) [Year]
    from @T
    group by year(CreatedDate)
    
    -- per month
    select
      sum(MoneySpent) Spent,
      year(CreatedDate) [Year],
      month(CreatedDate) [Month]
    from @T
    group by year(CreatedDate), month(CreatedDate)
    
    -- per half year
    select
      sum(MoneySpent) Spent,
      year(CreatedDate) [Year],
      case when month(CreatedDate) <= 6 then 'First' else 'Second' end [HalfYear]
    from @T
    group by year(CreatedDate), case when month(CreatedDate) <= 6 then 'First' else 'Second' end
    
    -- per quarter
    select
      sum(MoneySpent) Spent,
      year(CreatedDate) [Year],
      ((month(CreatedDate)-1) % 4)+1 [Quarter]
    from @T
    group by year(CreatedDate), ((month(CreatedDate)-1) % 4)+1
    
    -- per week
    select
      sum(MoneySpent) Spent,
      year(CreatedDate) [Year],
      datepart(iso_week, CreatedDate) [Week]
    from @T
    group by year(CreatedDate), datepart(iso_week, CreatedDate)
    

    Result

    Spent       Year
    ----------- -----------
    65          2010
    220         2011
    
    Spent       Year        Month
    ----------- ----------- -----------
    60          2010        1
    220         2011        1
    5           2010        12
    
    Spent       Year        HalfYear
    ----------- ----------- --------
    60          2010        First
    220         2011        First
    5           2010        Second
    
    Spent       Year        Quarter
    ----------- ----------- -----------
    60          2010        1
    220         2011        1
    5           2010        4
    
    Spent       Year        Week
    ----------- ----------- -----------
    220         2011        1
    5           2010        52
    60          2010        53
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to build a search query on Customers table join with orders table
I need to build an update query from an associative array from a POST
I need to build a dynamic linq query with or operators. I have seen
I need to build query in SQL to get rows the have text like
I need to build query, that return result with network topology with more than
I need to build a configurable query builder that allows the user to compound
I need some help to build SQL Query. I have table having data like:
I need build in web query capability similar to what you can do in
I need to build a query with 4 columns (sql 2005). Column1: Product Column2:
Ok I need to build a query based on some user input to filter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.