mysql - 在 SQL 表中容纳航路点

标签 mysql sql

我目前正在创建一个表来存储出租车预订。

enter image description here

Id - booking id

CustId - id of customer who is being picked up

DriverId - id of driver who is picking up customers

PickupAddr - pickup location

PickupLat - lat coordinate of pickup location

PickupLon - lon coordinate of pickup location

DropoffAdr - drop off location

DropoffLat - lat coordinate of dropoff location

DropoffLon - lon coordinate of dropoff location

Mileage - distance between PickupAddr and DropoffAddr, including any other stops made

Stops - number of waypoints/stops during journey

Price - what this customer has to pay for this part in the journey

我目前面临的问题是我不知道如何处理航路点。

例如如果您已在A接您前往B,但决定在旅途中在A1和A2停下来接一些 friend (当然都是提前预订的)

重组当前表格以适应这种情况的最佳方式是什么?

它应该作为单独的行还是列?由于这些数据是动态的(即无法预测客户在旅程中的接送次数),我应该实现什么目标。

最佳答案

由于这是一对多关系,因此它应该是一个单独的表:

  • id - 航点 ID
  • booking_id - FK 到 booking
  • sequence - 行程中此航点的顺序
  • addr - 航点地址
  • lat - 航路点的纬度
  • long - 航路点的经度

如果需要,您可以从 bookings 表中删除 PickupXXXDropoffXXX 列,而只需使用航点表即可。上车可能是第一个路径点,下车可能是最后一个路径点。

关于mysql - 在 SQL 表中容纳航路点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24981100/

相关文章:

mysql - 提取Logstash中的特定键和值

php - 使用 PHP 在 iOS 社交网络应用程序中发送好友请求并添加好友?

sql - 仅使用 SQL 将 Blob 从 MySQL 数据库导出到文件

mysql - 获取 MySQL 转储,将其恢复到具有原始列超集的表中

sql - 以原子方式标记并返回数据库中的一组行

mysql - 错误 1452 : Cannot add or update a child row: a foreign key constraint fails

sql - mysql 数据库中列中值的计数

php - 在for循环中存储mysql中的变量

sql - 在 postgres 的存储过程中将查询传递给 row_to_json 函数

sql - 设置 SQL Server 存储过程的默认参数