gpt4 book ai didi

sql - 如何在 SQL Server 中连接字符串消息和列值

转载 作者:行者123 更新时间:2023-12-03 09:19:26 26 4
gpt4 key购买 nike

我正在尝试为我的 sql 查询结果添加自定义消息,但找不到确切的方法来实现这一点。下面是我在 sql 查询中尝试的结果。

Select 
'The Maximum Rating of the city' " + city + " 'is=' " + MAX(rating) + "
From
CUSTOMER
Where
CITY is not null
Group by
CITY;

最佳答案

删除双引号和最后一个+运算符

Select 'The Maximum Rating of the city '+city+' is = '+ cast(MAX(rating) as varchar(50))
from CUSTOMER
where CITY is not null
group by CITY;

如果您使用的是Sql Server 2012+,那么您可以使用Concat不需要显式转换的函数

Select Concat('The Maximum Rating of the city ',city,' is = ', MAX(rating))
from CUSTOMER
where CITY is not null
group by CITY;

关于sql - 如何在 SQL Server 中连接字符串消息和列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34237358/

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