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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:26:38+00:00 2026-05-13T11:26:38+00:00

I need to write queries to find out new users and regular users .

  • 0

I need to write queries to find out new users and regular users.

new users are the ones whose uuid appeared in last 24 hours (from now minus the time query is fired) in table2 and was not there before.

regular users are the ones whose uuid appeared in last day in table2 and was also there at least once in the last 3 days.

In addition to this only records with id > 10 and ip != 2 are to be considered.

table1 is a temporary table containing dates. I am not able to figure out how to achieve this with help of joins. Please help me.


table2

    +----+---------------------+------+------+
    | id | ts                  | uuid | ip   |
    +----+---------------------+------+------+
    |  1 | 2010-01-10 00:00:00 | uid1 |    5 |
    |  2 | 2010-01-10 00:00:00 | uid2 |   14 |
    |  3 | 2010-01-10 00:00:00 | uid3 |   11 |
    |  4 | 2010-01-11 00:00:00 | uid4 |   16 |
    |  5 | 2010-01-11 00:00:00 | uid5 |    4 |
    |  6 | 2010-01-13 00:00:00 | uid6 |    2 |
    |  7 | 2010-01-10 00:00:00 | uid1 |    1 |
    |  8 | 2010-01-11 00:00:00 | uid2 |   10 |
    |  9 | 2010-01-12 00:00:00 | uid1 |    1 |
    | 10 | 2010-01-13 00:00:00 | uid4 |    1 |
    | 11 | 2010-01-09 21:00:00 | uid1 |    1 |
    | 12 | 2010-01-09 21:30:00 | uid1 |    2 |
    | 13 | 2010-01-10 05:00:00 | uid2 |    3 |
    | 14 | 2010-01-10 12:00:00 | uid1 |    1 |
    | 15 | 2010-01-10 12:00:00 | uid3 |    1 |
    | 16 | 2010-01-10 21:00:01 | uid1 |    7 |
    | 17 | 2010-01-11 01:00:00 | uid2 |   14 |
    | 18 | 2010-01-11 05:00:00 | uid2 |   11 |
    | 19 | 2010-01-11 17:59:00 | uid4 |   13 |
    | 20 | 2010-01-11 06:00:00 | uid5 |   12 |
    | 21 | 2010-01-11 18:01:00 | uid1 |   14 |
    | 22 | 2010-01-12 23:05:00 | uid4 |   17 |
    | 23 | 2010-01-13 12:01:23 | uid6 |   13 |
    +----+---------------------+------+------+
    23 rows in set (0.00 sec)

table1

    +------------+
    | ts         |
    +------------+
    | 2010-01-10 |
    | 2010-01-11 |
    | 2010-01-12 |
    | 2010-01-13 |
    +------------+
    4 rows in set (0.00 sec)

Output in case of new users taken at 18:00

+------------+-------+
| ts         | users |
+------------+-------+
| 2010-01-10 |     3 |
| 2010-01-11 |     2 |
| 2010-01-12 |     0 |
| 2010-01-13 |     1 |
+------------+-------+
4 rows in set (0.00 sec)

MySQL table dump

DROP TABLE IF EXISTS `table1`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `table1` (
  `ts` date NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

INSERT INTO `table1` VALUES ('2010-01-10'),('2010-01-11'),('2010-01-12'),('2010-01-13');

DROP TABLE IF EXISTS `table2`;
CREATE TABLE `table2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ts` datetime DEFAULT NULL,
  `uuid` varchar(20) DEFAULT NULL,
  `ip` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

INSERT INTO `table2` VALUES (1,'2010-01-10 00:00:00','uid1',5),(2,'2010-01-10 00:00:00','uid2',14),(3,'2010-01-10 00:00:00','uid3',11),(4,'2010-01-11 00:00:00','uid4',16),(5,'2010-01-11 00:00:00','uid5',4),(6,'2010-01-13 00:00:00','uid6',2),(7,'2010-01-10 00:00:00','uid1',1),(8,'2010-01-11 00:00:00','uid2',10),(9,'2010-01-12 00:00:00','uid1',1),(10,'2010-01-13 00:00:00','uid4',1),(11,'2010-01-09 21:00:00','uid1',1),(12,'2010-01-09 21:30:00','uid1',2),(13,'2010-01-10 05:00:00','uid2',3),(14,'2010-01-10 12:00:00','uid1',1),(15,'2010-01-10 12:00:00','uid3',1),(16,'2010-01-10 21:00:01','uid1',7),(17,'2010-01-11 01:00:00','uid2',14),(18,'2010-01-11 05:00:00','uid2',11),(19,'2010-01-11 17:59:00','uid4',13),(20,'2010-01-11 06:00:00','uid5',12),(21,'2010-01-11 18:01:00','uid1',14),(22,'2010-01-12 23:05:00','uid4',17),(23,'2010-01-13 12:01:23','uid6',13);
  • 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-13T11:26:38+00:00Added an answer on May 13, 2026 at 11:26 am

    You can join the table on itself to search for entries for the same user that are more than a day old. When there’s no day-old match, fields in the left joined table will be NULL.

    For example:

    select     
      YEAR(cur.ts) as year
    , MONTH(cur.ts) as month
    , DAY(cur.ts) as day
    , case when old.uuid is null then 1 else 0 end as IsNewUser
    , count(distinct cur.uuid) as Users
    from       table2 cur
    left join  table2 old
    on         cur.uuid = old.uuid
               and old.ip <> 2
               and old.id > 10
               and cur.ts - old.ts > 1
    where      cur.ip <> 2
               and cur.id > 10
    group by   year, month, day, IsNewUser
    order by   year, month, day, IsNewUser
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a program used internally where different users will have different
I need to write a Delphi application that pulls entries up from various tables
I need to write code that picks up PGP-encrypted files from an FTP location
I know how to write SQL queries and can get the results I need.
I need write an update statement that used multiple tables to determine which rows
I need to write a Java Comparator class that compares Strings, however with one
I need to write a web application using SQL Server 2005, asp.net, and ado.net.
I need to write a java script. This is supposed to validate if the
I need to write an extension method on a byte[]. Is that possible?
I need to write test cases for my application. I've chosen NUnit. Please let

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.