SQL 在 SQLite 中获取数字的下限值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7129249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:46:44  来源:igfitidea点击:

Getting the floor value of a number in SQLite?

sqlsqlitefloor

提问by Adam Smith

I have a SQLite database with a table containing the scores of some league players in a bowling center. I'm trying to get the average of the Score column for each player ID. The problem with this is I only need the whole part of the average, and it should not be rounded (example: an average of 168.99 should return 168, not 169).

我有一个 SQLite 数据库,其中包含一个表,其中包含保龄球中心的一些联盟球员的得分。我正在尝试获取每个玩家 ID 的 Score 列的平均值。问题是我只需要平均值的整个部分,而不应该四舍五入(例如:168.99 的平均值应该返回 168,而不是 169)。

When trying to find something like this on Google, I only found solutions for SQL Server and some others, but not SQLite, so if anyone can help me with this, I'd really appreciate it!

当试图在谷歌上找到类似的东西时,我只找到了 SQL Server 和其他一些的解决方案,但没有找到 SQLite,所以如果有人能帮我解决这个问题,我真的很感激!

So far, I'm using ROUND(AVG(s1.Score),2) and I'm truncating the extra part in my Java program that uses the database by converting it to a String, removing the unwanted part and then casting it to an Integer, but I'd rather do it all in SQL if possible.

到目前为止,我正在使用 ROUND(AVG(s1.Score),2) 并且我正在截断使用数据库的 Java 程序中的额外部分,方法是将其转换为字符串,删除不需要的部分,然后将其转换为一个整数,但如果可能的话,我宁愿在 SQL 中完成所有操作。

回答by Derek Kromm

You can just use cast it to an integer. It will truncate it, which is equivalent to floor.

您可以使用将其强制转换为整数。它会截断它,相当于 floor。

回答by ded'

You can use round(value - 0.5) (seen here)

您可以使用 round(value - 0.5) (见此处