如何在MySQL的BigQuery中提取时间?
extract()
与一起使用方法提取cast()
。以下是语法-
select extract(minute from cast(yourColumnName as time)) as anyAliasName from yourTableName;
让我们创建一个表-
mysql> create table demo15 −> ( −> value time −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo15 values('10:30:45'); mysql> insert into demo15 values('06:34:55');
使用select语句显示表中的记录-
mysql> select *from demo15;
这将产生以下输出-
+----------+ | value | +----------+ | 10:30:45 | | 06:34:55 | +----------+ 2 rows in set (0.00 sec)
以下是从时间提取分钟的查询-
mysql> select extract(minute from cast(value as time)) as Minute from demo15;
这将产生以下输出-
+--------+ | Minute | +--------+ | 30 | | 34 | +--------+ 2 rows in set (0.00 sec)