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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:44:46+00:00 2026-05-20T18:44:46+00:00

I posted about this a few weeks ago, but I don’t think I asked

  • 0

I posted about this a few weeks ago, but I don’t think I asked the question clearly because the answers I got were not what I was looking for. I think it’s best to start again.

I’m trying to query a database to retrieve the number of unique entries over time. The data looks something like this:

Day | UserID
1 | A
1 | B
2 | B
3 | A
4 | B
4 | C
5 | D

I’d like the query result to look this this

Time Span | COUNT(DISTINCT UserID)
Day 1 to Day 1 | 2
Day 1 to Day 2 | 2
Day 1 to Day 3 | 2
Day 1 to Day 4 | 3
Day 1 to Day 5 | 4

If I do something like

SELECT COUNT(DISTINCT `UserID`) FROM `table` GROUP BY `Day`

, the distinct counts will not consider user IDs of previous days.

Any Ideas? The data set I’m using is quite large, so multiple-queries and post processing takes a long time (that’s how I’m currently doing it).

Thanks

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

    You can use a subquery

    Sample table

    create table visits (day int, userid char(1));
    insert visits values
    (1,'a'),
    (1,'b'),
    (2,'b'),
    (3,'a'),
    (4,'b'),
    (4,'c'),
    (5,'d');
    

    The query

    select d.day, (select count(distinct userid) from visits where day<=d.day)
    from (select distinct day from visits) d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few days ago, I posted this question and this question asking about how
Last Updated: 2009-08-11 2:30pm EDT A few days ago I posted this question about
i have posted a few hours ago question about newtons method,i got answers and
I have already posted a question about this, but the situation has changed sufficiently
This is a spin off from another question I posted a few days ago
I posted this question a few days ago, and I have some follow up
I posted a question a few days ago about importing data to an InDesign
I posted a question a few days ago about a linked list in C.
I posted a question a few months ago about sharing resource dictionaries across assemblies
I posted about this before to a degree, but after a few days of

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.