为什么嵌套的转换不适用于MySQL? (它确实使用sql Server)
select cast(cast(myColumn as decimal(5,2)) as int) from myTable
最佳答案
根据the manual:
原文链接:https://www.f2er.com/mysql/433733.html
CAST(expr AS type)
[…]
CONVERT(expr,type)
[…]The
type
can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
所以,只需按照手册:
SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS SIGNED) FROM myTable
要么
SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS UNSIGNED) FROM myTable