SQL查询错误 [英] Bug With SQL Query
问题描述
运行SQL查询时遇到问题.我有一个Access数据库,其中包含名为Products的表.该表包含两列ProductName和UnitPrce. 单价"列中的值可以在小数点后最多包含4位数字,但是我只需要显示一位数字.当我运行此查询时
I have faced a problem when I run a SQL query. I have an Access database which contains table named Products. This table contains two columns ProductName and UnitPrce. Values in column UnitPrice can contain up to 4 digits after decimal but I need to display only one digit. When I run this query
SELECT Products.ProductName, ROUND(Products.UnitPrice, 1) AS Price
FROM Products
ORDER BY Products.ProductName
结果表中的值未四舍五入,但是如果我运行这样的查询
Values in the resulting table are not rounded, but if I run query like this
SELECT Products.ProductName, ROUND(Products.UnitPrice * 1, 1) AS Price
FROM Products
ORDER BY Products.ProductName
结果表中的值将四舍五入.我不明白为什么第一个查询不起作用?
列UnitPrice的类型为Single
Values in the resulting table are rounded. I don''t understand why the first query does not work?
The type of column UnitPrice is Single
推荐答案
字段UnitPrice的类型是什么?
看看这个链接 [
What is the type of the field UnitPrice?
Have a look at this link[^].
Products.UnitPrice * 1
Products.UnitPrice * 1
显然,这将改变结果的数据类型,这很可能就是为您舍入的结果.
请不要向自己发布答案.编辑您的帖子.我已经删除了帖子,并为您移动了答案.
This will obviously change the datatype of the result, and probably is what is doing the rounding for you.
Please do not post answers to yourself. Edit your post. I have deleted the post and moved your answer there for you.
这篇关于SQL查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!