0

我有一个我也在划分的 SQL SUM,但我想将精度设置在第十位,例如 10.1 而不是 10.12。你会怎么做呢?这是我的 SQL 语句:

 SELECT DISTINCT PAINT_LINE, SUM(HOURS_REQUIRED/WORKING_DAYS) AS HOURS_REQUIRED,
  TO_CHAR(WEEK_START, 'YYYY/MM/DD') AS WEEK_START FROM 
 DCSI.PAINTYEARLYPAINTHRSPROJECTIONS WHERE USER_ID = :UserID AND WEEK_START>=SYSDATE-7
  AND WEEK_START<=SYSDATE+63 GROUP BY WEEK_START, PAINT_LINE ORDER BY WEEK_START DESC, PAINT_LINE

我想将 HOURS_REQUIRED 设置为十分之一的精度,但我不知道该怎么做。

谢谢!

4

2 回答 2

2

尝试:

ROUND(SUM(HOURS_REQUIRED/WORKING_DAYS),1) 作为 HOURS_REQUIRED

看:

http://msdn.microsoft.com/en-us/library/ms175003.aspx

于 2012-07-16T21:08:42.553 回答
2

最好的方法是将其转换为具有正确精度的数字:

cast(<val> as numeric(8,1))

例如。

在你的情况下,这将是:

cast(SUM(HOURS_REQUIRED/WORKING_DAYS) as numeric(8, 1)) AS HOURS_REQUIRED
于 2012-07-16T21:23:17.367 回答