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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:06:10+00:00 2026-05-26T06:06:10+00:00

So I want to compare new users to returning users in a table by

  • 0

So I want to compare new users to returning users in a table by month. I have a table that contains each action with a username and a date stamp.

I can easily pull users that performed an action in, for example, January 2011. To see see if each user is new I need to then run their username against all previous records (prior to January 2011).

In my fumblings I came up with the following:

  SELECT ini.username,
         MIN(ini.datetime) AS firstAction,
         COUNT(ini.datetime) AS numMonth,
         (SELECT COUNT(*) 
            FROM tableActions tot
           WHERE tot.username = ini.username
             AND tot.datetime < '201101%' 
             AND tot.datetime > '201001%') AS numTotal
    FROM tableActions ini
   WHERE DATETIME >= '201101%' 
     AND DATETIME < '201102%'
GROUP BY ini.username
ORDER BY firstAction

It doesn’t error, but it doesn’t finish either. Seems to be quite intense.

  • 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-26T06:06:11+00:00Added an answer on May 26, 2026 at 6:06 am

    You can re-write the query to be (assuming tableactions.datetime is a DATETIME data type):

       SELECT ini.username,
              MIN(ini.datetime) AS firstAction,
              COUNT(ini.datetime) AS numMonth,
              x.numTotal
         FROM tableActions ini
    LEFT JOIN (SELECT tot.username,
                      COUNT(*) AS numTotal
                 FROM tableActions tot
                WHERE tot.datetime > '2010-01-01'
                  AND tot.datetime < '2011-01-01'
             GROUP BY tot.username) x ON x.username = ini.username
        WHERE ini.datetime BETWEEN '2011-01-01' AND '2011-01-31'
     GROUP BY ini.username
     ORDER BY firstAction
    

    Might help to have an index on username at a minimum, though a covering index using username, datetime is worth considering.

    The datetime comparison looks suspect – LIKE is the only to support wildcards.

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

Sidebar

Related Questions

I have a search form field that I want to compare with multiple columns
I want to prevent users from using webcam emulators, I have done that in
I want to compare two ms-access .mdb files to check that the data they
I want to compare two times in VB.net: I have 1:42:21 PM and I
Using VB6 I want to compare the system date, if the exe should not
I want to compare the user's birthday against today's date and get the number
I have devise + a scaffold house created, and I want that a user
I want to compare the current value of an in-memory Hibernate entity with the
I want to compare and contrast the various source control systems out there. Any
I want to compare the first few bytes in byte[] with a string. How

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.