MySql 5.6列级查询

时间:2013-05-01 11:19:53

标签: mysql

我在MySQL 5.6中尝试以下SQL:

select Test=1 from ALL_FILES_INFO; 

但是我收到了一个错误。

错误代码:1054。“字段列表”中的未知列“测试”

这是像这样的事情

Select Name,
       Amount=(select Amount from EmployeeAmount where EmployeeName=Name)
 from Employee;

相同的代码在Microsoft SQL Server中正常运行。

2 个答案:

答案 0 :(得分:2)

SQL Server有一种说明列别名的替代方法,据我所知,这可以完全相同,并且可以在MySQL和SQL Server上运行;

SELECT 1 AS Test from ALL_FILES_INFO; 

SQLFiddle for SQL Server
SQLFiddle for MySQL

答案 1 :(得分:1)

加入表格比使用相关子查询更好:

SELECT Employee.Name, EmployeeAmount.Amount
FROM   Employee
  JOIN EmployeeAmount ON EmployeeAmount.EmployeeName = Employee.Name