Order by time value : Time « Data Type « SQL / MySQL






Order by time value

     
mysql>
mysql> CREATE TABLE temporal_val
    -> (
    ->  d       DATE,
    ->  dt      DATETIME,
    ->  t       TIME,
    ->  ts      TIMESTAMP
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO temporal_val (d, dt, t, ts)
    ->  VALUES
    ->          ('1970-01-01','1884-01-01 12:00:00','13:00:00','1980-01-01 02:00:00'),
    ->          ('1999-01-01','1860-01-01 12:00:00','19:00:00','2021-01-01 03:00:00'),
    ->          ('1981-01-01','1871-01-01 12:00:00','03:00:00','1975-01-01 04:00:00'),
    ->          ('1964-01-01','1899-01-01 12:00:00','01:00:00','1985-01-01 05:00:00')
    -> ;
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM temporal_val;
+------------+---------------------+----------+---------------------+
| d          | dt                  | t        | ts                  |
+------------+---------------------+----------+---------------------+
| 1970-01-01 | 1884-01-01 12:00:00 | 13:00:00 | 1980-01-01 02:00:00 |
| 1999-01-01 | 1860-01-01 12:00:00 | 19:00:00 | 2021-01-01 03:00:00 |
| 1981-01-01 | 1871-01-01 12:00:00 | 03:00:00 | 1975-01-01 04:00:00 |
| 1964-01-01 | 1899-01-01 12:00:00 | 01:00:00 | 1985-01-01 05:00:00 |
+------------+---------------------+----------+---------------------+
4 rows in set (0.00 sec)

mysql>
mysql> SELECT * FROM temporal_val ORDER BY t;
+------------+---------------------+----------+---------------------+
| d          | dt                  | t        | ts                  |
+------------+---------------------+----------+---------------------+
| 1964-01-01 | 1899-01-01 12:00:00 | 01:00:00 | 1985-01-01 05:00:00 |
| 1981-01-01 | 1871-01-01 12:00:00 | 03:00:00 | 1975-01-01 04:00:00 |
| 1970-01-01 | 1884-01-01 12:00:00 | 13:00:00 | 1980-01-01 02:00:00 |
| 1999-01-01 | 1860-01-01 12:00:00 | 19:00:00 | 2021-01-01 03:00:00 |
+------------+---------------------+----------+---------------------+
4 rows in set (0.00 sec)

mysql>
mysql> drop table temporal_val;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
  








Related examples in the same category

1.TIME: Time type value is in the form '23:59:59'
2.Sorting by Time of Day