1

我有一个关于如何根据员工性别找到工资歧视的问题。我有 MS Acess 2007,必须使用 SQL 查询来解决

请记住,这是在我将 3 个表连接到一个多表查询之后。在这个查询中,每当我想用例如 a 对任何列进行排序时ORDER BY Salary,它都会给我一个错误标志,说:

Syntax error (missing operator) in query expression 'Salary'
WHERE JobClass.JobClassID = Employees.JobClassID 
AND Department.DepartmentID = Employees.DepartmentID'.

我想尝试在查询中对多个列进行排序。

多表查询代码如下:

SELECT JobClass.JobClassID, JobClassName, Department.DepartmentID, 
       DepartmentName, LastName, FirstName, Title, Sex, Years, Salary
FROM  JobClass, Employees, Department
ORDER BY 'Salary'
WHERE JobClass.JobClassID = Employees.JobClassID AND Department.DepartmentID = Employees.DepartmentID;
4

2 回答 2

1

Order by Clause 应该在 where 子句之后

像这样试试

SELECT JobClass.JobClassID, JobClassName, Department.DepartmentID, 
       DepartmentName, LastName, FirstName, Title, Sex, Years, Salary
FROM  JobClass, Employees, Department
WHERE JobClass.JobClassID = Employees.JobClassID AND Department.DepartmentID = Employees.DepartmentID
ORDER BY Salary

选择语法

SELECT [predicate] { * | table.* | [table.]field1 [AS alias1] [, [table.]field2 [AS alias2] [, …]]}     
FROM tableexpression [, …] [IN externaldatabase]     
[WHERE… ]    
[GROUP BY… ]     
[HAVING… ]     
[ORDER BY… ]     
[WITH OWNERACCESS OPTION]
于 2014-03-05T06:41:19.923 回答
0

除非 Access '07 完全无视标准 SQL(我不认为它如此),否则您的 SQL 语法是关闭的。

与其放在子句ORDER BY 之前,不如把它放在.WHEREWHERE

于 2014-03-05T06:36:49.757 回答