检查 mysql 查询是否提供了问题的最佳解决方案
Checking if mysql query provides the best solution to the question
List the Employee names and address of all the employees working in
the EmployeeType whose code is 1 and the hourly rate of pay is €40.
我想知道这是否是从上述问题中检索信息的最佳方式
SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e JOIN EmployeeType et ON e.EmployeeType = et.EmployeeType
HAVING e.EmployeeCode = (1) AND et.TotalPay = (40);
我不会在此查询中使用 'HAVING',我更喜欢 WHERE 条件或在连接时添加更多参数。您可以阅读关于 HAVING 的内容 LINK
Having 与 WHERE 条件有点不同,因为它是在查询结果之后应用的。
具有简单 WHERE 条件的第一个解决方案
SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e
INNER JOIN EmployeeType et ON e.EmployeeType = et.EmployeeType
WHERE e.EmployeeCode = '1' AND et.TotalPay = '40';
第二种解决方案在加入时添加更多参数
SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e
INNER JOIN EmployeeType et ON (e.EmployeeType = et.EmployeeType AND et.TotalPay = '40')
WHERE e.EmployeeCode = '1' ;
List the Employee names and address of all the employees working in the EmployeeType whose code is 1 and the hourly rate of pay is €40.
我想知道这是否是从上述问题中检索信息的最佳方式
SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e JOIN EmployeeType et ON e.EmployeeType = et.EmployeeType
HAVING e.EmployeeCode = (1) AND et.TotalPay = (40);
我不会在此查询中使用 'HAVING',我更喜欢 WHERE 条件或在连接时添加更多参数。您可以阅读关于 HAVING 的内容 LINK Having 与 WHERE 条件有点不同,因为它是在查询结果之后应用的。
具有简单 WHERE 条件的第一个解决方案
SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e
INNER JOIN EmployeeType et ON e.EmployeeType = et.EmployeeType
WHERE e.EmployeeCode = '1' AND et.TotalPay = '40';
第二种解决方案在加入时添加更多参数
SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e
INNER JOIN EmployeeType et ON (e.EmployeeType = et.EmployeeType AND et.TotalPay = '40')
WHERE e.EmployeeCode = '1' ;