圆形函数查询2到3个参数?

时间:2018-10-18 14:27:09

标签: sql sql-server sql-server-2016

我试图在此查询中找到每位用户的收入,但似乎在此错误中运行。

select concat('$',format(cast(round(sum(total)/count(distinct(customers))),2) 
as int),N'N','en-US') 
from table

我的错误:

  

round函数需要2到3个参数

2 个答案:

答案 0 :(得分:2)

我怀疑你的意思:

SELECT CONCAT('$',FORMAT(CAST(ROUND(SUM(Total)/COUNT(DISTINCT customers),2) AS int),N'N'),'en-US') 
FROM [table];

但是,实际上,您需要担心表示层中值的格式(FORMATCONCAT不需要在那里)。

此外,为什么要先ROUND({expr},2),然后再CAST({expr} AS int)呢?为什么不ROUND({expr},0)

答案 1 :(得分:1)

例如使用2作为舍入长度

round(sum(total)/count(distinct(customers)),2)