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

  • Home
  • SEARCH
  • 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 8216705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:13:26+00:00 2026-06-07T12:13:26+00:00

How can I select one, most recent NID , per every 7 days, per

  • 0

How can I select one, most recent NID, per every 7 days, per UID, starting count back from today.

If today is July 11, the following table

+-----+------------+-----+
| NID |  timestamp | UID |
+-----+------------+-----+
|   1 | 1341719851 |   8 | //July 7
|   2 | 1341115051 |   8 | //July 1
|   3 | 1341547051 |   8 | //July 6
|   4 | 1341719851 |   8 | //July 8
|   5 | 1341979051 |   8 | //July 11
|   6 | 1341806251 |   9 | //July 9
|   7 | 1341460651 |   9 | //July 5
|   8 | 1341892651 |   9 | //July 10
+-----+------------+-----+

Will output this:

+-----+------------+-----+
| NID |  timestamp | UID |
+-----+------------+-----+
|   2 | 1341115051 |   8 | //July 1
|   5 | 1341979051 |   8 | //July 11
|   8 | 1341892651 |   9 | //July 10
+-----+------------+-----+

In the last 7 days, most recent NID for each user is '5' and '8', in the prior 7 days, most recent NID is '2', and so on…

I’m assuming, Group By will do the trick; but I don’t have a clue where to start.

UPDATE

This is the query that worked, based on the top answer:

SELECT nid, timestamp, uid, weeks_ago
FROM (
    SELECT nid, timestamp, uid, FLOOR(
        (UNIX_TIMESTAMP()- timestamp)/604800
    ) weeks_ago
    FROM `table`
    ORDER BY timestamp DESC
) x
GROUP BY uid, weeks_ago 
  • 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-07T12:13:28+00:00Added an answer on June 7, 2026 at 12:13 pm
    select nid, max(timestamp), uid, weeks_ago
    from (select nid, timestamp, uid, floor(datediff(now(), from_unixtime(timestamp))/7) weeks_ago
          from mytable) x
    group by nid, uid, weeks_ago
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can i perform select single node from IXMLDOMElement ,if its possible give me one
Essentially what I want to do is select the most recent message between one
I'd like to generate a select form field, where a user can select one
How can one select a specific sibling of a context node using jQuery? Specifically,
Can someone tell me how can I select the Row under the one on
How can I do one single query with both an INSERT and SELECT in
How can I set Emacs gdb so that it shows the most recent command
I want to return the most recent ten (complete) rows from a table, but
I need to select the most recent 2 rows by unix timestamp. I would
Having a Zend_Form with a Zend_Form_Element_Select on it, i can set ONE option selected

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.