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 8522227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:03:53+00:00 2026-06-11T07:03:53+00:00

I have a table in which i have columns like : ItemId Date CountUser

  • 0

I have a table in which i have columns like :

ItemId   Date        CountUser       CountUserPast7Days
1        20120101    20              null
1        20120102    15              null
1        20120208    12              null
2        20120209    65              null
2        20120611    32              null
2        20120615    20              null
3        20120901    45              null

I want to write an query to update CountUserPast7Days based on – group by the data on two parameters – ItmeId and Date(past 7 days) and sum the column CountUser. So the data should look like –

ItemId   Date        CountUser    CountUserPast7Days
1        20120101    20           20 
1        20120102    15           35 
1        20120208    12           27 
2        20120209    65           65
2        20120611    32           32
2        20120615    20           52
3        20120901    45           45
  • 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-06-11T07:03:54+00:00Added an answer on June 11, 2026 at 7:03 am

    Your example output is buggy, since there is more than a month between 2012/01/02 and 2012/02/08, but I got your point all the same. What you are looking for is a self-join:

    SELECT S1.Item, S1.Date, SUM(S2.Count) As CountPast7 FROM SlidingHitCount S1
      INNER JOIN SlidingHitCount S2 on S1.Item = S2.Item
    WHERE S2.Date BETWEEN DATEADD(dd, -7, S1.Date) AND S1.Date
    GROUP BY S1.Item, S1.Date
    

    Obviously I called your table “SlidingHitCount.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+
I have a table which has 4 columns: id, twitter_id, date, time . I'd
I have a table with 3 columns which looks like this: File User Rating
I have a table yrs_order which has columns like: header_key (primary key) order_no ref1
Suppose we have a table which holds information about person. Columns like NAME or
I have table which contains columns like SiteID (identity_Col) SiteName POrderID Location Address Cluster
I have a table which has 4 columns. Date login, date logout, time login,
I have a table which looks something like the following (first row is columns):
How to tell django-tables2 which columns I would like to have in table? I
I have a mysql table which columns are post_id and post_msg. Now I want

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.