要将时间戳转换为月份,请使用FROM_UNIXTIME()方法,如以下语法所示:selectmonth(from_unixtime(yourColumnName))fromyourTableName;
让我们首先创建一个表-mysql>createtableDemoTable1457
->(
->Valuebigint
->);
使用插入命令在表中插入一些记录-mysql>insertintoDemoTable1457values(1570207117);
mysql>insertintoDemoTable1457values(1548947534);
mysql>insertintoDemoTable1457values(1575213134);
使用select语句显示表中的所有记录-mysql>select*fromDemoTable1457;
这将产生以下输出-+------------+
|Value|
+------------+
|1570207117|
|1548947534|
|1575213134|
+------------+
3rowsinset(0.00sec)
以下是将时间戳转换为月份的查询-mysql>selectmonth(from_unixtime(Value))fromDemoTable1457;
这将产生以下输出-+-----------------------------+
|month(from_unixtime(Value))|
+-----------------------------+
|10|
|1|
|12|
+-----------------------------+
3rowsinset(0.00sec)