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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:33:11+00:00 2026-06-10T11:33:11+00:00

I have a table like below: uid nid points date reason 36 116 2

  • 0

I have a table like below:

uid nid     points  date                        reason
36  116     2       2012-08-28 11:52:12         session
31  110     2       2012-08-23 15:47:47         session
36  115     2       2012-08-27 11:52:48         session

as u can see uid is not unique, it can be repeated. What i need is to select sum of points for every id between date(30 days before). For example: sum of uid36 = to 4.
What i have tried:

$start_time = mktime(0, 0, 0, $today["mon"], ($today["mday"] - 30), $today["year"]);//30 days before
$end_time = time();
$query = db_query("SELECT uid,sum(points), date FROM users_history WHERE date BETWEEN '$start_time' AND '$end_time'");

but how to select for every id

  • 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-10T11:33:12+00:00Added an answer on June 10, 2026 at 11:33 am

    You need GROUP BY uid, and date is meanless in your query if you are using aggregate function SUM.

    SELECT uid, SUM(points) 
    FROM users_history 
    WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 30 day) AND NOW() 
    GROUP BY uid
    

    And if there is no future date, then you only need

    WHERE date >= DATE_SUB(CURDATE(), INTERVAL 30 day)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table like below ID User Date Location 1 Tom 6-Mar-2012 US 2
I have a table like below and its rows can be added and removed
I have a table that has data like below(sorted by date) COL_A | COL_B
I have table tblTask with data like below. TID StartTime Uid WId 1 2011-06-06
I have a mysql table like below: id name points 1 john 4635 3
I have a table like below: Table A ---------- ID Field1 Field2 Field3 1
I have a table like below: EmployeeId EmployeeName RequestId RequestName EmployeeId RequestId I need
I have a table like below: COL1 | COL2 | COL3 ______________________ ITEM1 |
e.g. If I have a table like below:- create table Categories(CategoryId int primary key,
need help in error in database pivot. i have table tamed table_score like below:

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.