简体   繁体   English

如何使用JPA查询舍入列值?

[英]How can I round a column value with a JPA query?

I need to compare for equality on a number stored in the database as a floating point number (this has to support multiple databases and I haven't got any control over how it's stored), but of course equality will only get you so far with an approximated value, so I need to round the column value like this: 我需要比较存储在数据库中作为浮点数的数字的相等性(这必须支持多个数据库,而且我对它的存储方式没有任何控制权),但是当然,相等性只会帮助您一个近似值,所以我需要对列值进行四舍五入:

select * from x where round(col, 2) = ?;

Unfortunately I can't seem to find a way of doing that in JPQL. 不幸的是,我似乎找不到在JPQL中实现此目标的方法。 Is there any way to achieve this (without changing the database)? 有什么方法可以做到这一点(无需更改数据库)?

I have two ideas to solve this problem: 我有两个想法可以解决这个问题:

  1. make a between query 进行两次查询

  2. use a native query 使用本地查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM