存储价格包的数据库布局

发布于 2024-10-12 05:46:18 字数 1043 浏览 0 评论 0原文

我正在开发一个应用程序,并寻找一个数据库模式来以与价格相关的有效方式存储产品销售。因此,我正在寻找一个数据库架构和一个示例查询来计算该月的价格

背景信息:

  • 产品价格基于该月的销售量
  • 相同的产品可以有不同的价格(取决于每个公司的价格协商) )
  • 需要能够在不影响早期销售/发票
  • 商店价格的情况下更改价格,无需增值税,增值税可以更改

到目前为止我所得到的内容如下:

销售

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-10-19 05:46:18

订单完成后,为什么不将销售价格和当前增值税值直接写入“销售”表中?这是历史数据,因此可以从产品表中复制它。

如果我正确理解您的“price_packages”表应该如何工作,它将是这样的:

SELECT
   product_id
   , price
FROM
   price_packages
WHERE
   NOW() BETWEEN valid_from AND valid_until
   AND $sales BETWEEN sales_min AND sales_max
   AND product_id IN ($product_ids)

将“$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:

SELECT
   product_id
   , price
FROM
   price_packages
WHERE
   NOW() BETWEEN valid_from AND valid_until
   AND $sales BETWEEN sales_min AND sales_max
   AND product_id IN ($product_ids)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文