sql - 如何查找小数点后两位以上的值?

标签 sql decimal

我正在验证数据并尝试查找单列 (allowed_amount) 中是否有任何值的小数位数超过 2 位(24.1145678、234.444、-1234.09012)。

with t1 as (
  select (allowed_amount - round(allowed_amount,2)) as ck
  from export_core_report_client_output
  where runid = '0c7c2d34-6cc3-43b0-ae4b-4bd8f4bddfb0'
) 
select min(ck) as min, max(ck) as max from t1

最佳答案

一种选择是使用以下公式:

SELECT
    num,
    CASE WHEN 100*num - CAST(100*num AS int) > 0 THEN 'yes' ELSE 'no' END AS field
FROM yourTable;

Demo

例如,对于值 24.1234,以上公式计算:

2412.34 - 2412 = 0.34 > 0

但是对于 24.12,我们得到:

2412 - 2412 = 0

关于sql - 如何查找小数点后两位以上的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56756728/

相关文章:

sql - 返回所有重复行

sql - 如何在绑定(bind)变量中传递空值

sql - Powershell SQL 查询结果转换为 XML

python-3.x - pandas.isnull() 不适用于十进制类型?

MySQL 防止小数字段四舍五入

sql - 在数据库中存储非常大的文件

sql - 使用 "Select INTO"表示数百万条记录

c# - 基于 C# 中出生日期的简单年龄计算器

mysql - mysql/phpmyadmin 中的 SQL 小数数据类型

asp.net-mvc - DisplayFormat 未应用于十进制值