gpt4 book ai didi

sql - 使选择语句输出带逗号的数字

转载 作者:行者123 更新时间:2023-12-01 13:34:38 26 4
gpt4 key购买 nike

我正在使用 SQL Server 并试图找出如何使 select 语句输出一个以逗号分隔的数字。我只能找到如何将数字转换为带逗号的数字,这不是我想要的。下面的代码是我试图输出为带逗号的数字的代码。现在,当您执行该语句时,它返回值 750000.00,我希望它返回 750,000.00。

代码:

select max(c.salary) as MaxSalary
from #Career c inner join
#Member m
on c.Member_ID = m.Member_ID
where m.age < 35

最佳答案

对于 SQL Server 2012 及更高版本,您可以使用 FORMAT()

select FORMAT(750000.00, 'N', 'en-us') AS 'Numeric Format' 


declare @table table(salary decimal(16,4))
insert into @table
values
(1234.00),
(64423.55)

select FORMAT(sum(salary), 'N', 'en-us') AS 'Numeric Format'
from @table

--or using your tables
select FORMAT(max(c.salary), 'N', 'en-us') AS 'Numeric Format'
from #Career c inner join
#Member m
on c.Member_ID = m.Member_ID
where m.age < 35

关于sql - 使选择语句输出带逗号的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44445115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com