舍入函数查询 2 到 3 个参数?



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

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

我的错误:

round 函数需要 2 到 3 个参数

我怀疑你的意思是:

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)

例如使用 2 作为长度以舍入

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

最新更新