Sql query data, how to query the data cout? every hour of the day

ladies and gentlemen, created_time stores string types in my database. How to query the amount of data per hour during the day? how to write this sql?

Feb.09,2022

mysql> desc test2;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id       | int(11)     | YES  |     | NULL    |       |
| time_rec | varchar(20) | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+

mysql> select * from test2;
+------+---------------------+
| id   | time_rec            |
+------+---------------------+
|    1 | 2018-12-12 12:12:12 |
|    2 | 2018-12-12 12:12:14 |
|    3 | 2018-12-12 13:12:12 |
|    4 | 2018-12-13 12:12:12 |
+------+---------------------+
4 rows in set (0.00 sec)

mysql> select count(*),left(time_rec,13) as hour_time from test2 where left(time_rec,10)='2018-12-12' group by hour_time; 
+----------+---------------+
| count(*) | hour_time     |
+----------+---------------+
|        2 | 2018-12-12 12 |
|        1 | 2018-12-12 13 |
+----------+---------------+
2 rows in set (0.00 sec)

you can use segmented queries:

select * from 
   (select count(*) from you_table where  ) as one,
   (select count(*) from you_table where  ) as two,
   ...
Menu