SELECT
storename,
sid,
lng,
lat,
distribution,
sqrt(
(
(
( { $lng }- lng ) * PI( ) * 12656 * cos( ( ( { $lat }+ lat ) / 2 ) * PI( ) / 180 ) / 180
) * (
( { $lng }- lng ) * PI( ) * 12656 * cos ( ( ( { $lat }+ lat ) / 2 ) * PI( ) / 180 ) / 180
)
) + (
( ( { $lat }- lat ) * PI( ) * 12656 / 180 ) * ( ( { $lat }- lat ) * PI( ) * 12656 / 180 )
)
) / 2 AS juli
FROM
".$GLOBALS['ecs']->table('store')."
HAVING
( juli <= distribution )
ORDER BY
juli ASC
LIMIT 1