gpt4 book ai didi

MySQL:选择字符串的 Concat 和结果 Concat 的长度

转载 作者:行者123 更新时间:2023-11-29 03:28:06 25 4
gpt4 key购买 nike

在我的 CREATE VIEW 中,我想:

SELECT CONCAT( t.str1, t.str2 ) AS Title, CHAR_LENGTH( Title ) AS Length

但这会产生错误:

Unknown column 'Title' in 'field list'.

无需连续连接相同字符串两次的正确方法是什么?

最佳答案

您不能引用您在 SELECT 中创建的别名,而是使用表达式:

SELECT CONCAT( t.str1, t.str2 ) AS Title,
CHAR_LENGTH(CONCAT( t.str1, t.str2 ) ) AS Length
FROM table_name t

如果需要可以使用子查询:

SELECT sub.Title, CHAR_LENGTH( sub.Title ) AS Length
FROM (
SELECT CONCAT( t.str1, t.str2 ) AS Title
FROM table_name t
) AS sub;

All-at-once operation :

"All-at-Once Operations" means that all expressions in the same logical query process phase are evaluated logically at the same time.

和:

We cannot use an alias in next column expression in the SELECT clause. In the query we create a corrected first name and we want to use it in next column to produce the full name, but the All-at-Once operations concept tells us you cannot do this because all expressions in the same logical query process phase (here is SELECT) are evaluated logically at the same time.

关于MySQL:选择字符串的 Concat 和结果 Concat 的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33723677/

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