存储价格包的数据库布局
我正在开发一个应用程序,并寻找一个数据库模式来以与价格相关的有效方式存储产品销售。因此,我正在寻找一个数据库架构和一个示例查询来计算该月的价格
背景信息:
- 产品价格基于该月的销售量
- 相同的产品可以有不同的价格(取决于每个公司的价格协商) )
- 需要能够在不影响早期销售/发票
- 商店价格的情况下更改价格,无需增值税,增值税可以更改
到目前为止我所得到的内容如下:
销售
sale_id --PK (auto_incr)
company_id
product_type --FK on products.product_type
sale_date
产品
product_id --PK (auto_incr)
company_id (company_id & product_type = Unique_key)
product_type
*price_packages*
product_id --FK on products.product_id
sales_min (total sales need to be between sales_min and sales_max)
sales_max
price
valid_from
valid_until
vat_id --FK on vat.vat_id
增值税
vat_id --PK (auto_incr)
vat_percentage
valid_from
valid_until
我认为“sales_max”有问题和“sales_min”列。我也怀疑这是否是存储东西的最佳方式。欢迎一些建议。 (如果可能的话,可以使用示例查询)
如何在不影响以前价格的情况下输入新价格。
I'm working on an application and looking for a database schema to store product sales in a efficient manner relating to the prices. So I'm looking for a database schema and an example query to calculate the price for that month
background info:
- the product price is based on the amount of sales for that month
- An identical product can have different prices (depending on price negotiation per company)
- need to be able to change prices without affecting earlier sales/invoices
- store prices without VAT, VAT can change
What I have got so far looks something like this:
sales
sale_id --PK (auto_incr)
company_id
product_type --FK on products.product_type
sale_date
products
product_id --PK (auto_incr)
company_id (company_id & product_type = Unique_key)
product_type
*price_packages*
product_id --FK on products.product_id
sales_min (total sales need to be between sales_min and sales_max)
sales_max
price
valid_from
valid_until
vat_id --FK on vat.vat_id
vat
vat_id --PK (auto_incr)
vat_percentage
valid_from
valid_until
I think that there is something wrong with the "sales_max" and "sales_min" columns. Also I'm doubting if this is the best way to store things. Some Advise is welcome. (if possible with an example query)
How would you enter new prices without affecting previous prices.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
订单完成后,为什么不将销售价格和当前增值税值直接写入“销售”表中?这是历史数据,因此可以从产品表中复制它。
如果我正确理解您的“price_packages”表应该如何工作,它将是这样的:
将“$sales”替换为该产品的销售数量(将计数器列添加到产品表中或从“sales”表中计算)
替换“$product_ids”包含实际订单中的产品。
如果您有疑问,请告诉我。
Why don't you write sale price and current VAT value directly into "sales" table when the order is done? This is historical data, so it's ok to duplicated it from products table.
If I understand correctly how your "price_packages" table is supposed to work it will be like this:
Replace "$sales" with number of sales for this product (either add counter column to products table or calculate it from "sales" table)
Replace "$product_ids" with products from the actual order.
Let me know if you have questions.