2

当我从 MySQL 5.0 升级到 5.1 时,SP 中的以下 SQL 语句停止使用错误代码 1064 - WHERE 子句中的列名无效 VARCLNO:

SELECT *, CLNO as VARCLNO, concat(CLCompany, CLSurname, CLFirstName, CLNO) as CLSort FROM Customer WHERE
 CLEditDate = (select max(CLEditDate) from Customer WHERE VARCLNO = CLNO )
 ORDER BY CLSort;

CUSTOMER 表的所有列都以 CL 开头。

非常感谢任何帮助。

4

1 回答 1

0

使用表别名尝试此查询:

SELECT *, 
      CLNO as VARCLNO, 
      concat(CLCompany, CLSurname, CLFirstName, CLNO) as CLSort 
FROM Customer AS T1 
      WHERE
         CLEditDate = (select max(CLEditDate) from Customer WHERE T1.CLNO = CLNO )
ORDER BY CLSort;
于 2013-08-20T13:00:41.850 回答