gpt4 book ai didi

Mysql 在 Select 语句中为列名添加前缀

转载 作者:行者123 更新时间:2023-11-29 11:09:21 33 4
gpt4 key购买 nike

我可能无法正确理解我的条款,因此无法在网络上找到答案。

我有 2 张这样的 table

customer_db - Customer Data
CustomerID CustomerName CustomerContact
1 John 1234
2 Anna 5678
3 Angel 2468

customer_channel - Chat Channel Name
ChannelName OnlineStatus
private-customer-1 YES
private-customer-2 NO

所以通常我会做这样的事情

Select a.OnlineStatus, b.CustomerName, b.CustomerContact FROM customer_db a,
customer_channel b WHERE a.CustomerID = b.ChannelName

其中存在“private-customer-”前缀,因此我无法进行匹配。

我尝试添加前缀,但不起作用。 如何在 WHERE 语句中向列名添加“文本前缀”来选择表?

Select a.OnlineStatus, b.CustomerName, b.CustomerContact FROM customer_db a,
customer_channel b WHERE a.CustomerID = 'private-customer-'+b.ChannelName

最佳答案

使用concat函数中,逗号(,)是老方法,尝试使用join:

SELECT
a.OnlineStatus,
b.CustomerName,
b.CustomerContact
FROM customer_db a
JOIN customer_channel b
ON a.CustomerID = concat('private-customer-', b.ChannelName)

关于Mysql 在 Select 语句中为列名添加前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40887816/

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