gpt4 book ai didi

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

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

在我的创建 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:选择字符串的连接和结果连接的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34003818/

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