Cast(字段名 as 转换的类型 ),其中类型可以为:
1、CHAR[(N)] 字符型
2、DATE 日期型
3、DATETIME 日期和时间型
4、DECIMAL float型
5、SIGNED int
6、TIME 时间型
例如表table1
date
2015-11-03 15:31:26
select cast(date as signed) as date from table1;
结果如下:
date
20151103153126
select cast(date as char) as date from table1;
结果如下:
date
2015-11-03 15:31:26
select cast(date as datetime) as date from table1;
结果如下:
date
2015-11-03 15:31:26
select cast(date as date) as date from table1;
结果如下:
date
2015-11-03
select cast(date as time) as date from table1;
结果如下:
date
15:31:26
这里date对应日期,time对应时间
————————————————
版权声明:本文为CSDN博主「Dongguo丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_37450089/article/details/80750994