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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:00:21+00:00 2026-05-22T18:00:21+00:00

Suppose you have a table of the form: create table user_activity ( user_id int

  • 0

Suppose you have a table of the form:

create table user_activity (
    user_id int not null, 
    activity_date timestamp not null, 
    ...);

It’s easy enough to select the number of unique user_id’s in the past 30 days.

select count(distinct user_id) from user_activity where activity_date > now() - interval 30 day;

But how can you select the number of unique user_ids in the prior 30 days for each of the past 30 days? E.g. uniques for 0-30 days ago, 1-31 days ago, 2-32 days ago and so on to 30-60 days ago.

The database engine is mysql if it matters

  • 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-22T18:00:22+00:00Added an answer on May 22, 2026 at 6:00 pm

    You could try using a sub query:

    SELECT DISTINCT `activity_date` as `day`, (
    SELECT count(DISTINCT `user_id`) FROM `user_activity` WHERE `activity_date` = `day`
    ) as `num_uniques`
    FROM `user_activity` 
    WHERE `activity_date` > NOW() - INTERVAL 30 day;
    

    This should give you the number of unique users for each day. However, I haven’t tested this since I don’t have the DB to work with.

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

Sidebar

Related Questions

Suppose I have the following table: CREATE TABLE EXAMPLETABLE ( ID NUMBER(10,0) NOT NULL,
Suppose I have a table like: create table { id numeric(5,3), code varchar(10) }
Suppose I have a massive table called inactiveUsers and a search form. I want
Please look at this query. select name form table Let suppose this returns 100
Suppose I have table A with a field that can be either 1 or
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose we have a table A: itemid mark 1 5 2 3 and table
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have a table . Now, I'm interested in Getting Useful Data Easily.
Suppose you have a table in SQL: Prices ------ 13.99 14.00 52.00 52.00 52.00

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.