简体   繁体   English

检查 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.列出在代码为 1 且每小时工资为 40 欧元的 EmployeeType 中工作的所有员工的姓名和地址。

I would like to know if this is the best way of retrieving information from the question above我想知道这是否是从上述问题中检索信息的最佳方式

SELECT e.EmployeeName , e.EmployeeAddress
FROM Employee e JOIN EmployeeType et ON e.EmployeeType = et.EmployeeType
HAVING e.EmployeeCode = (1) AND et.TotalPay = (40);

I wouldn't use 'HAVING' in this query, I would prefer WHERE condition or add more parameters on join.我不会在此查询中使用“HAVING”,我更喜欢 WHERE 条件或在加入时添加更多参数。 You can read about HAVING on this LINK Having is little bit different then WHERE condition, because its applied after querying results.您可以在此LINK上阅读有关 HAVING 的信息,Having 与 WHERE 条件略有不同,因为它在查询结果后应用。

1st solution with simple WHERE condition第一个具有简单 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';

2nd solution add more parameters on join第二种解决方案在加入时添加更多参数

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' ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM