-- Finds the 5 closest customers to warehouse_id = 2
-- and orders the results by distance
select /*+ordered*/
c.customer_id,
c.cust_first_name,
c.cust_last_name,
sdo_nn_distance (1) distance
from warehouses w,
customers c
where w.warehouse_id = 2
and sdo_nn (c.cust_geo_location, w.wh_geo_location, 'sdo_num_res=5', 1) = 'TRUE'
order by distance;
|