这个问题是延长我的前面的问题的一部分, 查找字符串号位置 。
我有表myTable
如下(myWord ==> VARCHAR(10))
++++++++++++
+ myWord +
++++++++++++
+ AB123 +
+ A413 +
+ X5231 +
+ ABE921 +
+ 15231 +
+ 523 +
+ ABC +
++++++++++++
我想,如下是。
++++++++++++++++++++++++++++++++
+ myWord + myPos + NewString +
++++++++++++++++++++++++++++++++
+ AB123 + 3 + AB +
+ A413 + 2 + A +
+ X5231 + 2 + X +
+ ABE921 + 4 + ABE +
+ 15231 + 1 + +
+ 523 + 1 + +
+ ABC + 999 + ABC +
++++++++++++++++++++++++++++++++
要得到上面的输出,我用下面的查询。
SELECT
myWord,
LEAST (
if (Locate('0',myWord) >0,Locate('0',myWord),999),
if (Locate('1',myWord) >0,Locate('1',myWord),999),
if (Locate('2',myWord) >0,Locate('2',myWord),999),
if (Locate('3',myWord) >0,Locate('3',myWord),999),
if (Locate('4',myWord) >0,Locate('4',myWord),999),
if (Locate('5',myWord) >0,Locate('5',myWord),999),
if (Locate('6',myWord) >0,Locate('6',myWord),999),
if (Locate('7',myWord) >0,Locate('7',myWord),999),
if (Locate('8',myWord) >0,Locate('8',myWord),999),
if (Locate('9',myWord) >0,Locate('9',myWord),999)
) as myPos,
if (LEAST (
if (Locate('0',myWord) >0,Locate('0',myWord),999),
if (Locate('1',myWord) >0,Locate('1',myWord),999),
if (Locate('2',myWord) >0,Locate('2',myWord),999),
if (Locate('3',myWord) >0,Locate('3',myWord),999),
if (Locate('4',myWord) >0,Locate('4',myWord),999),
if (Locate('5',myWord) >0,Locate('5',myWord),999),
if (Locate('6',myWord) >0,Locate('6',myWord),999),
if (Locate('7',myWord) >0,Locate('7',myWord),999),
if (Locate('8',myWord) >0,Locate('8',myWord),999),
if (Locate('9',myWord) >0,Locate('9',myWord),999)
)=999,myWord,SUBSTR(myWord,1,LEAST (
if (Locate('0',myWord) >0,Locate('0',myWord),999),
if (Locate('1',myWord) >0,Locate('1',myWord),999),
if (Locate('2',myWord) >0,Locate('2',myWord),999),
if (Locate('3',myWord) >0,Locate('3',myWord),999),
if (Locate('4',myWord) >0,Locate('4',myWord),999),
if (Locate('5',myWord) >0,Locate('5',myWord),999),
if (Locate('6',myWord) >0,Locate('6',myWord),999),
if (Locate('7',myWord) >0,Locate('7',myWord),999),
if (Locate('8',myWord) >0,Locate('8',myWord),999),
if (Locate('9',myWord) >0,Locate('9',myWord),999)
)-1)) as NewString
FROM myTable;
我的问题是
作为MyPos列船名后,为什么我不能在另一列使用该名称如下图所示的查询?
SELECT
myWord,
LEAST (
if (Locate('0',myWord) >0,Locate('0',myWord),999),
if (Locate('1',myWord) >0,Locate('1',myWord),999),
if (Locate('2',myWord) >0,Locate('2',myWord),999),
if (Locate('3',myWord) >0,Locate('3',myWord),999),
if (Locate('4',myWord) >0,Locate('4',myWord),999),
if (Locate('5',myWord) >0,Locate('5',myWord),999),
if (Locate('6',myWord) >0,Locate('6',myWord),999),
if (Locate('7',myWord) >0,Locate('7',myWord),999),
if (Locate('8',myWord) >0,Locate('8',myWord),999),
if (Locate('9',myWord) >0,Locate('9',myWord),999)
) as myPos,
if (myPos=999,myWord,SUBSTR(myWord,1,myPos-1)) as NewString
FROM myTable;
但是,这给了我错误的
Unknown column 'myPos' in 'field list':
在这里看到更多的细节
请建议我可以做些什么,使这个查询使用别名短 。