【发布时间】:2014-05-19 15:15:28
【问题描述】:
目前的数据库结构包括:
- 国家/地区(country_id、country_name)
- 城镇(town_id、country_id、town_name)
- 地区(area_id、town_id、area_name)
- 车站(station_id、area_id、station_name)
- 优惠(offer_id、offer_name、车站)
报价表中的站点列包含以下格式的站点 ID:
|station_id_1|station_id_2|station_id_4|......|
我对 JOINED 查询非常熟悉,但在这种情况下,很难创建一个查询,该查询可以 COUNT(country_id) FROM countries OR town_id FROM 实际有报价的城镇...我如何加入车站列 FROM 报价表与实际站一起以便之后加入较低级别的表?这可能吗?
提前谢谢你
【问题讨论】:
-
我删除了我的答案,您应该添加 n-to-n 表
offers_stations (offer_id, station_id)并连接优惠和车站。保持这样的station_id_1|station_id_2|station_id_4永远不会很好。