为此,您可以使用聚合函数MIN()
和GROUP BY。让我们首先创建一个表-
mysql> create table DemoTable1870 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int, ShippingTimestamp varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(10,'1570645800'); mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(10,'1546194600'); mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(11,'1573324200'); mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(11,'1557599400');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1870;
这将产生以下输出-
+----+-------+-------------------+ | Id | Value | ShippingTimestamp | +----+-------+-------------------+ | 1 | 10 | 1570645800 | | 2 | 10 | 1546194600 | | 3 | 11 | 1573324200 | | 4 | 11 | 1557599400 | +----+-------+-------------------+ 4 rows in set (0.00 sec)
这是从MySQL&Minus;中的时间戳获取第一个日期的查询。
mysql> select min(ShippingTimestamp) from DemoTable1870 group by Value;
这将产生以下输出-
+------------------------+ | min(ShippingTimestamp) | +------------------------+ | 1546194600 | | 1557599400 | +------------------------+ 2 rows in set (0.00 sec)