Search code examples
mysqlmysql-error-1064

Mysql query discrepancy


I have 2 mysql queries but getting different result for both queries, although first query seems to be give more results.

MySQL [mydb1]> select count(*) from user_id where 
create_time>='2017-07-28' and create_time<='2017-07-31';

+----------+
| count(*) |
+----------+
| 65150086 |
+----------+

MySQL [mydb1]> select count(*) from user_id where 
create_time>='2017-07-28 16:30:00' and create_time<='2017-07-31 14:30:00';
+----------+
| count(*) |
+----------+
| 79679998 |
+----------+



+----------------+-------------+------+-----+-------------------+-----------------------------+
| Field          | Type        | Null | Key | Default           | Extra                       |
+----------------+-------------+------+-----+-------------------+-----------------------------+
| id             | bigint(11)  | NO   | PRI | NULL              | auto_increment              |
| user_id        | varchar(45) | NO   | UNI | NULL              |                             |
| name           | varchar(45) | YES  | MUL | NULL              |                             |
| create_time    | datetime    | YES  |     | NULL              |                             |
| update_time    | timestamp   | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+----------------+-------------+------+-----+-------------------+---------

Solution

  • create_time<='2017-07-31' means create_time<='2017-07-31 00:00:00' (starting of the day)

    you might have data that is between '2017-07-31 00:00:00' and '2017-07-31 14:30:00'

    Run a query to check if you have data in the above interval.