简体   繁体   English

MS ACCESS和SQL:通过查询舍入到两位小数

[英]Ms ACCESS and SQL: round to two decimals through query

I use queries to calculate all kinds of supplier information (average lead time, total spend for that supplier, average price, etc.). 我使用查询来计算各种供应商信息(平均提前期,该供应商的总支出,平均价格等)。 All output is shown in listboxes in forms in Ms ACCESS. 所有输出都显示在ACCESS女士表格中的列表框中。

Example of a calculated number: 计算数字的示例:

在此处输入图片说明

How do I format the output of these queries to be rounded to two decimals? 如何将这些查询的输出格式化为两位小数? I've been playing around with the listbox settings but cannot find it there. 我一直在玩着列表框设置,但在那里找不到它。 I believe I will have to do it in the query itself, but I'm not sure how. 我相信我将不得不在查询本身中执行此操作,但是我不确定如何执行。

Query code for the above number: 以上编号的查询代码:

SELECT Avg([Item Master].PlannedLeadTime) AS AverageLeadTime
FROM [Item Master]
WHERE ((([Item Master].DateStamp)>=[Forms]![History Supplier Tool]![List2] And ([Item Master].DateStamp)<=[Forms]![History Supplier Tool]![List3]) AND (([Item Master].SupplierName)=[Forms]![History Supplier Tool]![List1]));

Note: List1 is a listbox where the user can select a certain supplier (for which the calculations are performed) and list2 and list3 are dates the user can select (as to determine a date range for the calculations). 注意:List1是一个列表框,用户可以在其中选择某个供应商(针对其进行计算),而list2和list3是用户可以选择的日期(以确定计算的日期范围)。

Access SQL has a rich function set one of which is the round function. Access SQL具有丰富的功能集,其中之一是round功能。

Example: 例:

SELECT Round(Avg([Item Master].PlannedLeadTime),2) AS AverageLeadTime
FROM [Item Master]
WHERE (...)

Further information: http://www.techonthenet.com/access/functions/numeric/round.php 更多信息: http : //www.techonthenet.com/access/functions/numeric/round.php

Use ROUND() Function: 使用ROUND()函数:

The ROUND() function is used to round a numeric field to the number of decimals specified. ROUND()函数用于将数字字段四舍五入为指定的小数位数。

SQL ROUND() Syntax: SQL ROUND()语法:

SELECT ROUND(column_name,decimals) FROM table_name;

|Parameter    |Description
________________________________________________    
|column_name  |Required. The field to round.
|decimals     |Required. Specifies the number of decimals to be returned.

So, Your required query will be: 因此,您所需的查询将是:

SELECT ROUND(AVG([Item Master].PlannedLeadTime),2) AS AverageLeadTime
FROM [Item Master]
WHERE ((([Item Master].DateStamp)>=[Forms]![History Supplier Tool]![List2]
      And ([Item Master].DateStamp)<=[Forms]![History Supplier Tool]![List3])                   AND (([Item Master].SupplierName)=[Forms]![History Supplier Tool]![List1]));

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

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