6

为什么嵌套转换在 MySQL 中不起作用?(它确实使用 SQL Server)

select cast(cast(myColumn as decimal(5,2)) as int) from myTable 

SQLFiddle 示例

4

2 回答 2

3

根据手册

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
于 2012-04-27T11:13:34.883 回答
0

此查询正在处理嵌套转换的概念。

cast(sum(cast(Column_name int)+ cast(Column_name as int)) as bigint) 作为来自 table_name 的付款

于 2015-12-14T06:56:06.570 回答