只是一个简单的问题-如何组织一个订单表,即当某人用id=1订购2倍的商品,用id=2订购3倍的商品时。
我之前的解决方案是将它保存为:products
列中的2x1,3x2
,然后分解()它,但效率非常低。
发布于 2011-07-30 23:47:52
我会选择3张桌子:
product
表--该表与订购系统完全独立,网站使用它只显示productsorder
表,该表存储订单的基本信息(如订购者、帐单地址等)order_product
连接表,指明每个订单包含哪些产品以及数量。最后一个表至少包含以下字段:
id_order
:orderid_production
的标识符: productquantity
的标识符:该产品在该订单中的购买次数发布于 2015-12-03 23:41:30
我认为公认的答案是非常好的,但我也会用customers
表来扩展它。
下面是我计划在我的项目中使用的结构的更完整的例子(还没有测试)……
CUSTOMERS table:
_id
name
address
tel
email
PRODUCTS table:
_id
name
price
ORDERS table:
_id
customer_id
datetime
ORDER_PRODUCTS table:
_id
order_id
product_id
product_quantity
...so,基本上,如果客户在他的订单中有3种不同的产品(例如,1个苹果,2个香蕉和4个帽子),那么我们将看到ORDERS
表中添加了1行,ORDER_PRODUCTS
表中添加了3行。
发布于 2020-03-30 00:08:13
这是另一个建议,稍微扩展一下:
customers表:
id
name
email
timestamps (created, modified, deleted)
customer_addresses:
id
customer_id
street
zip_code
city
state
country
type (enum or varchar indexed - options would be 'billing', 'shipping')
订单:
id
customer_id
subtotal (without taxes, discount, shipping, etc.)
total (including additional order line items)
billing_address_id (foreign key from customer_addresses)
shipping_address_id (foreign key from customer_addresses)
status (paid, checkout, canceled, failed, expired...)
payment type
timestamps (created, modified, deleted)
order_items:
id
order_id
item_id
item_quantity
price
order_line_items (可选,用于存储运费、折扣、税费等额外费用):
id
order_id
type
amount
timestamps
https://stackoverflow.com/questions/6884219
复制相似问题