如何使用LENGTH()函数使用order

时间:2017-11-20 11:04:32

标签: mysql

我正在尝试执行以下查询但是,每次我得到错误的结果并且其返回的总值为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);

1 个答案:

答案 0 :(得分: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 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;