我想修剪SQL中的名称。例如,我的数据有一个名称,即美国航空公司和“美国航空公司”;美国航空公司“;

我想修剪SQL中的名称。例如,我的数据有一个名称,即美国航空公司和“美国航空公司”;美国航空公司“;,sql,oracle,substr,Sql,Oracle,Substr,我想修剪SQL中的名称。例如,我的数据有一个名称,即美国航空公司和“美国航空公司”。 我期待着写一个sql查询 select customer_name, requests. from Table1. where code = "blue" --输出: 寻找产出 American airlines 31 Alaska Airline 45 有人能帮忙吗 谢谢您是否尝试过使用sum按分组 select replace(customer_name,'"','') as customer_name

我想修剪SQL中的名称。例如,我的数据有一个名称,即美国航空公司和“美国航空公司”。 我期待着写一个sql查询

select customer_name, requests.
from Table1.
where code = "blue"
--输出:

寻找产出

American airlines 31
Alaska Airline 45
有人能帮忙吗
谢谢

您是否尝试过使用
sum
分组

select replace(customer_name,'"','') as customer_name, sum(requests)
from Table1.
where code = "blue"
group by replace(customer_name,'"','');

使用replace将“替换为空”

REPLACE(string1, string_to_replace, replacement_string)
e、 g


哦,当我发帖的时候。”“被删除了。因此,其中一个客户名称是美国航空公司,另一个记录是“美国航空公司”-在名称的开头和结尾都有“group by将只是group by American airline和“American airlines”,我希望看到它们的汇总。字符串需要在SQL中用单引号括起来。
“蓝色“
是该上下文中的一个列名,
'blue'
是一个字符串常量您的编辑已将双引号从输出中完全删除,因此现在看起来像是简单的聚合;但它仍然在标题和问题主体的一部分。所以现在更不清楚了。您可能应该防止出现这种情况,例如,对输入数据进行归一化处理。
REPLACE(string1, string_to_replace, replacement_string)
select replace(customer_name,'"','') as cusname ,sum(requests)
.....
group by cusname