gpt4 book ai didi

php - 与货币和国家相关的产品的数据库结构

转载 作者:太空宇宙 更新时间:2023-11-03 11:54:00 25 4
gpt4 key购买 nike

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

这是结构:

cities:

id
city_name
status
country

products:

id
product_name
product_price
status
metadata

countries:

id
country_name
currency
status

currencies

id
currency
symbol
code

目前,

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

现在,每个产品在不同的城市会有不同的价格。

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

最佳答案

使用规范化有帮助。

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

关于php - 与货币和国家相关的产品的数据库结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34103233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com