How to include this SQL subquery for absolute number's value?

江枫思渺然 提交于 2020-01-06 19:36:49

问题


I have this query written for Access DB.

queryText = "SELECT Technicians.ID, firstName, lastName, Technicians.[Zone],
COUNT(technicianAssignedId) AS JobsDone, 
MAX(Faults.timeCompleted) AS LastJobTime,
MIN(Technicians.[Zone] - & faultZone &) AS Distance ' MIN has no use
FROM Technicians LEFT OUTER JOIN Faults ON
Technicians.ID = Faults.technicianAssignedID 
WHERE Specialization = '" & specialization & "'
`AND Availability = 'available' 
GROUP BY Technicians.ID, firstName, lastName, Availability,` Technicians.[Zone], Specialization 
ORDER BY 7 DESC"

I have this to get absolute value

SELECT CASE
WHEN value < 0 THEN value * -1
ELSE number *1 END
AS VALUE
FROM DB;

Now the column with Distance alias may end up as negative number which I need as positive by using (* -1), but I can't figure out how to put this together.

Thanks for any help


回答1:


try

ABS(Technicians.[Zone] - & faultZone &) AS Distance 

See ABS doc




回答2:


Why can't you just use the absolute function, ABS?




回答3:


ABS() is working for all SQL versions



来源:https://stackoverflow.com/questions/12805207/how-to-include-this-sql-subquery-for-absolute-numbers-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!