SQL - 测试数字字段是否包含整数
SQL - test if numeric field is holding an integer
我有数字(来自我的select)
col1 col2
1. 3.6 and 3
2. 3.6 and 5
我想要这个
if(col1/col2 = integer)
update column
else(col1/col2 = decimal number)
update column
知道如何得到数字是整数还是小数吗?
您可以使用模 1 (% 1),如果余数为零,那么您就有 'integer'。例如,SQL 服务器:
if (col1 / col2 ) % 1 = 0
-- integer
else
-- decimal
我有数字(来自我的select)
col1 col2
1. 3.6 and 3
2. 3.6 and 5
我想要这个
if(col1/col2 = integer)
update column
else(col1/col2 = decimal number)
update column
知道如何得到数字是整数还是小数吗?
您可以使用模 1 (% 1),如果余数为零,那么您就有 'integer'。例如,SQL 服务器:
if (col1 / col2 ) % 1 = 0
-- integer
else
-- decimal