--------- .333333(所影响的行数为 1 行) */select cast(1.0/3 as decimal(18,2)) /*
-------------------- .33(所影响的行数为 1 行) */
你首先要理解 / 這個的意思, 看sql online bookResult Types Returns the data type of the argument with the higher precedence. For more information about data type precedence, see Data Type Precedence. If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.
Res The actual value returned by the / operator is the quotient of the first expression divided by the second expression.
数据类型问题,你可以看看: select cast(1 as dec(8,2))/3
附上,Data Type Precedencesql_variant (highest) datetime smalldatetime float real decimal money smallmoney bigint int smallint tinyint bit ntext text image timestamp uniqueidentifier nvarchar nchar varchar char varbinary binary (lowest)
/*
---------
.333333(所影响的行数为 1 行)
*/select cast(1.0/3 as decimal(18,2))
/*
--------------------
.33(所影响的行数为 1 行)
*/
看sql online bookResult Types
Returns the data type of the argument with the higher precedence. For more information about data type precedence, see Data Type Precedence. If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.
Res
The actual value returned by the / operator is the quotient of the first expression divided by the second expression.
select cast(1 as dec(8,2))/3
datetime
smalldatetime
float
real
decimal
money
smallmoney
bigint
int
smallint
tinyint
bit
ntext
text
image
timestamp
uniqueidentifier
nvarchar
nchar
varchar
char
varbinary
binary (lowest)
select 1.0/3
select cast(1.0/3 as decimal(18,2))