为什么MySQL中的嵌套转换无法使用?(在SQL Server中可以)
select cast(cast(myColumn as decimal(5,2)) as int) from myTable
select cast(cast(myColumn as decimal(5,2)) as int) from myTable
所以,只需按照手册操作即可。
CAST(expr AS type)
[...]
CONVERT(expr,type)
[...]
type
可以是以下值之一:
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
这个查询基于嵌套转换的概念。
从表名中选择cast(sum(cast(Column_name int )+ cast(Column_name as int)) as bigint)作为payment
UNSIGNED
,再将结果解释为有符号的INT
,这样做的目的是什么?这难道不会和直接执行CAST(myColumn AS INT)
有相同的效果吗? - eggyalselect * from tab where cast(cast(myColumn as decimal(5,2)) as int) = cast(myColumn as decimal(5,2))
- juergen d