我正在寻找能够考虑餐馆设置的半径限制并且只向用户返回有效餐馆的查询。这比典型情况稍微复杂一点,因为半径距离通常是静态值。
这是具有半径限制的餐厅餐桌:
CREATE TABLE IF NOT EXISTS grabatakeaway.restaurant (
`restaurant_id` int(8) UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(128) NOT NULL,
`delivery_radius` int(4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
地址表存储地址的长度和纬度:
CREATE TABLE IF NOT EXISTS grabatakeaway.address (
`address_id` int(8) UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
`address` text NOT NULL,
`city` varchar(128) NOT NULL,
`state_province` varchar(128),
`zip_post` varchar(32) NOT NULL,
`latitude` float(16, 12) NOT NULL,
`longitude` float(16, 12) NOT NULL,
FOREIGN KEY (country_id) REFERENCES grabatakeaway.country(country_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
这些表格允许将用户或餐馆分配到地址
CREATE TABLE IF NOT EXISTS grabatakeaway.user_address (
`user_address_id` int(16) UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
`user_id` int(16) UNSIGNED NOT NULL,
`address_id` int(8) UNSIGNED NOT NULL,
`primary_address` tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES grabatakeaway.user(user_id),
FOREIGN KEY (address_id) REFERENCES grabatakeaway.address(address_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS grabatakeaway.restaurant_address (
`restaurant_address_id` int(16) UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
`restaurant_id` int(8) UNSIGNED NOT NULL,
`address_id` int(8) UNSIGNED NOT NULL,
FOREIGN KEY (restaurant_id) REFERENCES grabatakeaway.restaurant(restaurant_id),
FOREIGN KEY (address_id) REFERENCES grabatakeaway.address(address_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
任何人对我如何解决这个问题都有任何想法?