【问题标题】:Database structure for products related to currencies and countries与货币和国家相关的产品的数据库结构
【发布时间】:2015-12-05 19:06:07
【问题描述】:

在我的申请中,有很多公司提供的产品/服务。

这是结构:

城市:

id
city_name
status
country

产品:

id
product_name
product_price
status
metadata

国家:

id
country_name
currency
status

货币

id
currency
symbol
code

目前,

  1. 一个国家有很多城市
  2. 一个国家有一种货币

现在,每种产品在不同的城市都有不同的价格。

如何根据城市映射产品价格? 什么是通用结构,它可以满足所有用例?

【问题讨论】:

  • 您想永远坚持每个国家/地区使用一种货币吗?你能显示实际的架构吗?如果您已经有一个架构,那么上述内容就不是很好了。
  • 你遇到了什么问题?
  • 我还没有定义架构。这只是一个计划好的架构。

标签: php mysql database laravel


【解决方案1】:

使用规范化会有所帮助。

cities table:
id
name
status
country_id (id in table countries)

countries table:
id
name
currency_id (id in table currencies)
status

products table:
id
name
**    product_price ** (should be removed from this table)
status
metadata 

currencies table:
id
currency
symbol
code

product_price_in_city table:
id
city_id     (id in table cities)
product_id  (id in table products)
product_price_in_city (just a number. currency and symbol should be retrieved from table currency. using JOINs.
**'city_id ,product_id' pair should be unique.**

cities:
ID | name       | country_id
1  | 'london'   | 98
2  | 'tokyo'    | 99

countries:
ID | name       | currency_id
98 | 'england'  | 121
99 | 'japan'    | 122

currencies:
ID | name       | symbol
121| 'Pound'    | 's1'
122| 'Yen'      | 's2'

products:
ID | name 
789| 'CD'
790| 'DVD'
791| 'Floppy !!!!'

product_price_in_city:
ID  | city_id  | product_id | product_price_in_city
9988| 1        | 789        | 667788
9989| 1        | 790        | 66779988
9990| 1        | 791        | 567
9991| 2        | 790        | 776655
9992| 2        | 791        | 998877

如你所见,

CD  in London is 667788   Pound
DVD in London is 66779988 Pound
DVD in Tokyo  is 776655   Yen

【讨论】:

  • 那么,product_price_in_city 将是城市和产品之间的多对五关系,对吧?
猜你喜欢
  • 2010-09-19
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 2014-09-15
  • 2015-05-10
  • 1970-01-01
  • 2014-08-21
  • 1970-01-01
相关资源
最近更新 更多