proximity - SQL - find row with values of two columns closest to X and Y -
i building website on wich people can infos based on weight , height. how 1 structure query give me row 2 specific values closest ones users enter?
i found this on stackoverflow , helpful. trying accomplish similar 2 values insted of 1.
if weight , height of equal importance, can use (linear)
select top 1 * tbl order abs(weight-@weight) + abs(height-@height)
a better option weigh differences, on scale, such making 0.01m (1cm) of height of equal
importance 1kg. square both sides well, deviation of 5cm , 5kg seen "closer" 10cm , 0kg.
(assuming inputs in kg , metres)
select top 1 * tbl order abs(weight-@weight)^2 + (abs(height-@height)*100)^2
Comments
Post a Comment