gpt4 book ai didi

mysql - 如何将 order by 与 LENGTH() 函数一起使用

转载 作者:行者123 更新时间:2023-11-29 18:11:17 32 4
gpt4 key购买 nike

我正在尝试执行以下查询,但是每次我都会得到错误的结果及其返回的总值 0 。请帮我解决这个问题。

SELECT content, ((LENGTH(content)-(LENGTH(REPLACE(content,'oracle',''))))*4+(LENGTH(content)-(LENGTH(REPLACE(content,'finance',''))))*3+(LENGTH(content)-(LENGTH(REPLACE(content,'functional',''))))*2+(LENGTH(content)-(LENGTH(REPLACE(content,'consultant',''))))*1)
FROM `jobs` order by ((LENGTH(content)-(LENGTH(REPLACE(content,'oracle',''))))*4+(LENGTH(content)-(LENGTH(REPLACE(content,'finance',''))))*3+(LENGTH(content)-(LENGTH(REPLACE(content,'functional',''))))*2+(LENGTH(content)-(LENGTH(REPLACE(content,'consultant',''))))*1);

最佳答案

您可以将列索引用作:

SELECT content, ((LENGTH(content)-  
(LENGTH(REPLACE(content,'oracle',''))))*4+(LENGTH(content)-
(LENGTH(REPLACE(content,'finance',''))))*3+(LENGTH(content)-
(LENGTH(REPLACE(content,'functional',''))))*2+(LENGTH(content)-
(LENGTH(REPLACE(content,'consultant',''))))*1)
FROM `jobs` ORDER BY 2;

或者使用列别名:

SELECT content, ((LENGTH(content)-  
(LENGTH(REPLACE(content,'oracle',''))))*4+(LENGTH(content)-
(LENGTH(REPLACE(content,'finance',''))))*3+(LENGTH(content)-
(LENGTH(REPLACE(content,'functional',''))))*2+(LENGTH(content)-
(LENGTH(REPLACE(content,'consultant',''))))*1) CONTENT_SIZE
FROM `jobs` ORDER BY CONTENT_SIZE;

关于mysql - 如何将 order by 与 LENGTH() 函数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47390518/

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