Answer the question
In order to leave comments, you need to log in
Create a stored procedure. What could be the problem?
There is a simple request. You need to create a stored procedure from this query.
Request:
SELECT
id, name, category, ROUND((
1000 * 6371 * ACOS (
COS ( RADIANS(51.42689) )
* COS( RADIANS( latitude ) )
* COS( RADIANS( longitude ) - RADIANS(31.42689) )
+ SIN ( RADIANS(51.522256) )
* SIN( RADIANS( latitude ) )
)
), 3) AS distance, address, latitude, longitude,
(SELECT name FROM localities WHERE id = locality_id) AS locality_name, locality_id
FROM shops
HAVING distance < 150
ORDER BY distance;
DROP PROCEDURE IF EXISTS `get_nearest_shops`;
DELIMITER //
CREATE PROCEDURE get_nearest_shops(
IN p_lat DOUBLE,
IN p_lng DOUBLE,
IN p_radius DOUBLE,
OUT p_id INT(10),
OUT p_name VARCHAR(45),
OUT p_category ENUM('undefined','auto','children_prod','food','game','book',
'electronics','beuty&health','fashin','footwear','clothing',
'sports','homewere','pet_prod','services','gift&flowers'),
OUT p_distance DOUBLE,
OUT p_latitude DOUBLE,
OUT p_longitude DOUBLE,
OUT p_locality VARCHAR(45),
OUT p_locality_id INT(10))
BEGIN
DECLARE sign_after_point INT(10) DEFAULT 3;
SELECT
id, name, category, ROUND((
1000 * 6371 * ACOS (
COS ( RADIANS(p_lat) )
* COS( RADIANS( latitude ) )
* COS( RADIANS( longitude ) - RADIANS(p_lng) )
+ SIN ( RADIANS(p_lat) )
* SIN( RADIANS( latitude ) )
)
), sign_after_point) AS distance, latitude, longitude,
(SELECT name FROM localities WHERE id = locality_id) AS locality,
locality_id
INTO
p_id, p_name, p_category, p_distance, p_latitude, p_longitude,
p_locality, p_locality_id
FROM shops
HAVING distance < p_radius
ORDER BY distance;
END;//
Answer the question
In order to leave comments, you need to log in
I'm shy to ask, but if you need the query to return several lines - why are you shoving its result into out parameters? No need to do this, just leave select without any parameters and it will return what you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question