0

我对 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) 

解决此问题的最佳方法是什么?

我可以在记录中插入吗?

4

1 回答 1

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 的值

于 2012-11-03T13:18:56.053 回答