我有一张包含位置及其匹配地址的表格:
CREATE TABLE IF NOT EXISTS `locations` (
`location_id` int(11) NOT NULL AUTO_INCREMENT,
`location_type` text NOT NULL,
`location_type_closer` text NOT NULL,
`location_tags` text NOT NULL,
`location_name` varchar(256) NOT NULL,
`matching_address` int(11) NOT NULL,
`description` varchar(1024) NOT NULL,
`impressum` varchar(1500) NOT NULL,
`visits` int(255) NOT NULL,
`rating` int(255) NOT NULL,
PRIMARY KEY (`location_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;
CREATE TABLE IF NOT EXISTS `addresses` (
`address_id` int(11) NOT NULL AUTO_INCREMENT,
`continent` text NOT NULL,
`country` text NOT NULL,
`country_short` text NOT NULL,
`state` text NOT NULL,
`state_short` text NOT NULL,
`state_closer` text NOT NULL,
`postal_code` text NOT NULL,
`town` text NOT NULL,
`town_short` text NOT NULL,
`street` text NOT NULL,
`street_number` text NOT NULL,
`lat` text NOT NULL,
`lon` text NOT NULL,
`rating` int(255) NOT NULL,
`type` text NOT NULL,
PRIMARY KEY (`address_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
我的目标是找到type=town
的地址,其中大多数地点都有特定的类型,例如餐馆。该位置的匹配地址为type=street
或type=street_number
而不是type=town
,因此我认为唯一可能的解决方案是过纬/长比较,但我不知道如何在SQL查询,尤其是表的JOIN。我怎么能这样做?