我正在搜索邮政编码“2600”并使用此邮政编码,我 找到lat&很长的这个邮政编码..通过使用lat&很久,我们可以得到 使用mysql的距离。
我需要使用发送邮政编码和交付来获得结果 距离。餐厅有送货方式,可通过邮政编码或 距离。
所以我需要得到搜索结果餐馆是什么 由邮政编码2600提供,也可根据距离提供..
Zipcode/ Postal Code : 2600 this zipcode lat : 55.669217 long: 12.402144
我的sql代码:
--
-- Table structure for table `restaurant`
--
CREATE TABLE IF NOT EXISTS `restaurant` (
`resid` int(11) NOT NULL AUTO_INCREMENT,
`resname` varchar(10) NOT NULL,
`res_lat` varchar(25) NOT NULL,
`res_long` varchar(25) NOT NULL,
`delivery_option` enum('Zipcode','Distance') NOT NULL DEFAULT 'Zipcode',
PRIMARY KEY (`resid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
--
-- Dumping data for table `restaurant`
--
INSERT INTO `restaurant` (`resid`, `resname`, `res_lat`, `res_long`, `delivery_option`) VALUES
(1, 'aaaa', '55.68015', '12.388287', 'Zipcode'),
(2, 'bbbbb', '55.702066', '12.549631', 'Distance'),
(3, 'ccccc', '55.760539', '12.473222', 'Zipcode'),
(4, 'dddddd', '55.2562927', '12.120411', 'Distance'),
(5, 'eeee', '55.68015', '12.388287', 'Zipcode');
--
-- Table structure for table `delivery_zipcode`
--
CREATE TABLE IF NOT EXISTS `delivery_zipcode` (
`deli_zip_id` int(11) NOT NULL AUTO_INCREMENT,
`restaurant_id` int(11) NOT NULL,
`delivery_zipcode` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`delivery_charge` float DEFAULT NULL,
PRIMARY KEY (`deli_zip_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED AUTO_INCREMENT=4 ;
--
-- Dumping data for table `delivery_zipcode`
--
INSERT INTO `delivery_zipcode` (`deli_zip_id`, `restaurant_id`, `delivery_zipcode`, `delivery_charge`) VALUES
(1, 1, '2600', 5),
(2, 5, '2600', 10),
(3, 1, '2500', 15);
--
-- Table structure for table `delivery_distance`
--
CREATE TABLE IF NOT EXISTS `delivery_distance` (
`deli_circle_id` int(11) NOT NULL AUTO_INCREMENT,
`restaurant_id` int(11) NOT NULL,
`delivery_distance` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`delivery_charge` float DEFAULT NULL,
PRIMARY KEY (`deli_circle_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED AUTO_INCREMENT=13 ;
--
-- Dumping data for table `delivery_distance`
--
INSERT INTO `delivery_distance` (`deli_circle_id`, `restaurant_id`, `delivery_distance`, `delivery_charge`) VALUES
(1, 1, '10', 5),
(2, 1, '20', 10),
(3, 1, '30', 15),
(4, 1, '40', 20),
(5, 2, '5', 3),
(6, 2, '10', 6),
(7, 2, '15', 9),
(8, 2, '20', 12),
(9, 3, '20', 2),
(10, 3, '40', 4),
(11, 4, '15', 10);
I'm using below query...
SELECT res.resid, res. resname, dist. delivery_distance, dist. delivery_charge,
ROUND(( (((acos(sin((55.669217*pi()/180)) * sin((res.res_lat*pi()/180))+cos((55.669217 *pi()/180)) * cos((res.res_lat*pi()/180)) * cos(((12.402144 - res.res_long)
*pi()/180))))*180/pi())*60*1.1515*1.609344) ),2) AS distance
FROM restaurant AS res
LEFT JOIN delivery_distance AS dist ON res.resid = dist. restaurant_id
LEFT JOIN delivery_zipcode AS zip ON res.resid = zip. restaurant_id
WHERE dist.delivery_distance IS NOT NULL AND
zip.delivery_zipcode = ‘2600’ AND res.delivery_option=’Zipcode’
GROUP BY res.resid
HAVING distance <= dist.delivery_distance AND res.delivery_option=’Distance’
我需要得到如下结果......
resid resname delivery_option distance zipcode
1 aaaaa Zipcode - 2600
4 ddddd Distance - -
5 eeeee Zipcode - 2600