我是MySQL的新手,我正在使用MySQL来处理基于订购系统的项目。
我有一张桌子:
Session Table:
PK Session_ID
Date: Session_Date
Delivery Table:
PK: Delivery_Type (eg. Firstclass, Secondclass)
Int: Delivery_TimeToDeliver (1, 2, 3, these represent the expected time to deliver)
Order Table:
PK: Order_ID: autonum + 1
FK: Delivery Type
Date: Delivery_EstimatedTime
我想添加订单的方法是根据会话ID基本上计算估计时间:
Delivery_EstimatedTime = (Session Date + Delivery_TimeToDeliver)
最好的方法是什么?
我可以在记录插入时执行此操作吗?
答案 0 :(得分:0)
你可以使用:
INSERT INTO Order(Delivery_Type, Delivery_EstimatedTime)
SELECT Delivery_Type, Session_Date + INTERVAL Delivery_TimeToDeliver DAY
FROM Session
LEFT JOIN Delivery ON (Delivery_Type = @Delivery_Type)
WHERE Session_ID = @Session_ID
您为@Delivery_Type和@Session_ID
添加值