我试图在此查询中找到每位用户的收入,但似乎在此错误中运行。
select concat('$',format(cast(round(sum(total)/count(distinct(customers))),2)
as int),N'N','en-US')
from table
我的错误:
round函数需要2到3个参数
答案 0 :(得分:2)
我怀疑你的意思:
SELECT CONCAT('$',FORMAT(CAST(ROUND(SUM(Total)/COUNT(DISTINCT customers),2) AS int),N'N'),'en-US')
FROM [table];
但是,实际上,您需要担心表示层中值的格式(FORMAT
和CONCAT
不需要在那里)。
此外,为什么要先ROUND({expr},2)
,然后再CAST({expr} AS int)
呢?为什么不ROUND({expr},0)
?
答案 1 :(得分:1)
例如使用2作为舍入长度
round(sum(total)/count(distinct(customers)),2)