简体   繁体   English

如何按订单存储销售

[英]How to store sales in groups of orders

For a purchase-scenario: 对于购买场景:

I have a table (PRODUCTS) that contain columns like NAME, TYPE, DEFAULTPRICE, ID and a table with sales (SALES) that contain columns like DATE, ID, PRICE, AMOUNT where ID in SALES is a foreign key to primary key ID in PRODUCTS. 我有一个表(PRODUCTS),其中包含诸如NAME,TYPE,DEFAULTPRICE,ID之类的列,以及一个具有销售(SALES)的表,其中包含诸如DATE,ID,PRICE,AMOUNT之类的列,其中SALES中的ID是其中的主键ID的外键产品。 Very simple, not much to mess up there. 很简单,没有太多麻烦。

This works fine as long as you insert one row of whichever product (and how many) at what total price. 只要您以总价插入任一行(和多少行)产品,此方法就可以正常工作。

BUT - let's say I want to design this system to support "basket"-kind of shopping. 但是-假设我要设计此系统以支持“购物篮”式的购物。 Ie a user selects several items that are not the same product ID, but gets a single ORDER ID that contains all the products that were included in the order, the amount of each product, the total price, date etc. 也就是说,用户选择了多个商品,这些商品不是同一商品ID,而是获得一个ORDER ID,该ID包含订单中包含的所有商品,每个商品的数量,总价,日期等。

How would one go about creating this? 人们将如何去创建它? I was thinking maybe creating a table called "ORDERS" and link every row from SALES to an ID from ORDERS - but I'm not sure. 我在想也许创建一个名为“ ORDERS”的表,并将SALES的每一行链接到ORDERS的ID-但我不确定。

You would create a table called Orders for each order. 您将为每个订单创建一个名为Orders的表。 It would have whatever information you want about the order. 它会包含您想要的有关订单的任何信息。

You would then have a table for the products in each order. 然后,您将获得每个订单中产品的表格。 A common name is OrderLines . 通用名称是OrderLines This would have an OrderId , linking it to the Orders table and a ProductId linking to the Products table. 这将具有一个OrderId ,将其链接到Orders表,以及一个ProductId链接到Products表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM