我有这个问题,我已经苦苦挣扎了几个小时,似乎找不到解决方案来解决它并得到正确的答案。
select distinct Person.Person.FirstName, Person.Person.LastName, MAX(HumanResources.EmployeePayHistory.Rate) - MIN(HumanResources.EmployeePayHistory.Rate) AS 'Difference'
from Person.Person
inner join HumanResources.EmployeePayHistory on HumanResources.EmployeePayHistory.BusinessEntityID=Person.BusinessEntityID
where
group by Person.FirstName, Person.LastName;
在第一个语句中,我使用 max 和 min 函数来查找员工的费率(如果已更改)之间的差异。
不使用 where 语句的结果,
Syed Abbas 0.00,
Kim Abercrombie 0.00,
Hazem Abolrous 0.00,
Pilar Ackerman 0.00,
Jay Adams 0.00,
David Bradley 13.50,
Alan Brewer 0.00,
Eric Brown 0.00,
Jo Brown 0.00
我想在 select 语句中使用 max-min 的结果来只给我更改费率的员工的结果,例如:David Bradley 13.50?