I
I
isour2015-05-12 04:23:28
Database design
isour, 2015-05-12 04:23:28

How are prices implemented?

Good afternoon. Essence of the question: There is a database, we enter into it information about what a person bought on 05/01/2015 (let's call it a CHECK):

  • position 1 - 500r
  • position 2 - 600r
  • position 3 - 100 rub

A month passes, and already 06/01/2015. Price lists are subject to change.
  • position 1 - 200r
  • position 2 - 300r
  • position 3 - 200r

Now I need to see this receipt for 05/01/2015. How is this usually done?
  • Some revision of the price list is being done. Here, if I need to calculate all checks for a month or a year, then with a large number of checks, this will work slowly.
  • Information about the fact that a person bought three goods at such and such a price is recorded in a separate table. In this case, a large redundancy of information is obtained, as far as I understand.
  • ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2015-05-12
@isour

What you have called "price revision" is being done.

M
marble, 2015-05-12
_

There is an orders table. in it what kind of person, contacts, date of purchase.
For example:
id | name | date
------------------
17| Vasily | 05/01/2015
There is a table purchases, in it line by line what kind of purchase, price, and the main identifier from the orders table. That is, three purchases = three entries.
id | order_id | price | name
------------------------------
1 | 17 | 100 | Tractor
2 | 17 | 200 | Bicycle
3 | 17 | 300 | Pot
If the base, let's say sql, then a query is made like this:
select o.name as fio, o.date, p.price, p.name as product_name from orders o inner join purchases p ON(o.id=p.order_id) where o.date='05/01/2015'
we get the following output:
fio | date | price | product_name
--------------------------------
Vasily | May 01, 2015 | 100 | Tractor
Vasily | May 01, 2015 | 200 | Bicycle
Vasily | May 01, 2015 | 300 | Pot
You don't have to drag anything out of o.* if you only want the price tag for the date. Or use between in the condition if you need a selection for a range of dates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question