我有一个包含EmployeeID和Weight的表。我需要获得列重量的MIN值和MAX值,然后将WeightLost计算为SUM(MIN - MAX)。
然后最后新列WeightLostLBS = WeightLost * 2.2
employeeid weight
1 100
1 120
结果将是
EmployeeID WeightLost Min Max WeightLostLBS
1 20 100 120 44
答案 0 :(得分:3)
这里你不需要总和。正常减法将起作用。
select EmployeeID, MAX(Weight) - MIN(Weight) as WeightLost, MIN(Weight), MAX(Weight), (MAX(Weight) - MIN(Weight))*2.2 as WeightLostLBS
from table
group by EmployeeID
答案 1 :(得分:0)
SELECT EmployeeID,
MAX(Weight) - MIN(Weight) AS WeightLost,
MIN(Weight) AS MIN,
MAX(Weight) AS MAX,
(MAX(Weight) - MIN(Weight))*2.2 AS WeightLostLBS
FROM table1
GROUP BY EmployeeID
<强>输出强>
EmployeeID WeightLost MIN MAX WeightLostLBS
1 20 100 120 44
<强>演示强>