如何从给定值的mysql数据库表中找到最接近的值,我想要做的是:
CASE1:如果我将输入2500输入pincode,那么我将从数据库中检索与该pincode值对应的记录。
CASE2:如果记录未退出输入的密码(2500),我必须得到最接近的值2500及其相应的记录。
存储过程我目前正在呼吁 CASE1 sp_findlocation('XXXXXXXX','2500',@ addresss)
DELIMITER $$
USE `test`$$
DROP PROCEDURE IF EXISTS `sp_findlocation`$$
CREATE PROCEDURE `sp_findlocation`(IN mobile VARCHAR(20),IN pincode VARCHAR(20),OUT address VARCHAR(100))
BEGIN
IF(pincode IS NOT NULL AND pincode!= '') THEN
SET @c1 = '';
SET @c2 = '';
SET @c3 = '';
SET @qry='select locality,store_name,contact_number INTO @c1,@c2,@c3 from test_upload where pin=? limit 1';
PREPARE stmt FROM @qry;
SET @c = pincode;
EXECUTE stmt USING @c;
DEALLOCATE PREPARE stmt;
IF(@c1!='' || @c2!=''||@c3!='') THEN
SET address= CONCAT(@c1, '|',@c2,'|',@c3);
ELSE
SET address= "No Result";
END IF;
ELSE
SET address="Please enter valid pin code";
END IF;
END$$
DELIMITER ;
我将如何制作记录,包括 CASE2 ?