【问题标题】:Data normalization from CSV来自 CSV 的数据标准化
【发布时间】:2014-03-22 05:19:53
【问题描述】:

我想弄清楚如何规范化表中的一些数据。无论我如何尝试,我仍然会得到重复组!谁能给我一些关于这些数据的指导?

这是我要规范化的数据:

LANDLORD                LANDLORD GROUP                  QUARTER YEAR    ESTIMATED   ACTUAL
Housing Leeds           Yorkshire LL                    3       2013    221         235
Housing Leeds           Yorkshire LL                    2       2014    206 
Manchester housing      Northwest housing associates    3       2012    134         130
Liverpool properties    Northwest housing associates    2       2012    539         592
Liverpool properties    Northwest housing associates    3       2014    567 
Manchester housing      Northwest housing associates    2       2013    157         157
Liverpool properties    Northwest housing associates    2       2014    527 
Housing Leeds           Yorkshire LL                    3       2012    238         240
Liverpool properties    Northwest housing associates    4       2012    585         460
Manchester housing      Northwest housing associates    1       2012    125         136
Manchester housing      Northwest housing associates    3       2014    150 
Liverpool properties    Northwest housing associates    3       2012    569         585
Housing Leeds           Yorkshire LL                    1       2013    195         214
Manchester housing      Northwest housing associates    2       2012    132         140
Manchester housing      Northwest housing associates    2       2014    152 
Liverpool properties    Northwest housing associates    2       2013    555         577
Housing Leeds           Yorkshire LL                    3       2014    215 
Manchester housing      Northwest housing associates    4       2014    114 
Manchester housing      Northwest housing associates    1       2014    140 
Manchester housing      Northwest housing associates    3       2013    160         157
Liverpool properties    Northwest housing associates    3       2013    528         537
Liverpool properties    Northwest housing associates    1       2014    596 
Housing Leeds           Yorkshire LL                    2       2012    226         231
Manchester housing      Northwest housing associates    4       2013    111 
Manchester housing      Northwest housing associates    1       2013    135         136
Housing Leeds           Yorkshire LL                    1       2014    231 
Liverpool properties    Northwest housing associates    4       2013    536 
Manchester housing      Northwest housing associates    4       2012    105         96
Liverpool properties    Northwest housing associates    1       2013    527         560
Housing Leeds           Yorkshire LL                    4       2013    226 
Housing Leeds           Yorkshire LL                    2       2013    198         214
Housing Leeds           Yorkshire LL                    4       2014    235 
Liverpool properties    Northwest housing associates    1       2012    494         536
Housing Leeds           Yorkshire LL                    4       2012    181         197
Liverpool properties    Northwest housing associates    4       2014    568 
Housing Leeds           Yorkshire LL                    1       2012    201         209

提前感谢您的帮助。

【问题讨论】:

  • 到目前为止您尝试过什么,您想要的结果是什么?看起来每一行都是独一无二的,您可以为 LandlordLandlord Group 创建一个查找表以节省一些空间。
  • 我想我通过尝试正常化来使事情复杂化。我创建了一个包含季度、估计和实际的表。然后我用 Quarter 和 Year 创建了另一个表。我使用第一个表中的 Quarter 作为外键。我想我是想减少季度和年度的重复。但是您对使用查找表的建议对我来说听起来要好得多。感谢您的帮助。

标签: mysql sql database database-design database-normalization


【解决方案1】:

正如 Goat CO 建议的那样,您可以在该表上创建两个引用表,即 LandlordLandLord Group。然后当然将它与您的主表相关联。

因此,在这种情况下,您可以拥有三个表,即 LandLordLandLordGroup 和可能的 LandRental 表。

那么您可能会拥有这些TablesFields

 Table  : LandLord
 Fields : LandLordID, LandLordName

 Table  : LandLordGroup
 Fields : LandLordGroupID, LandLordGroupName

 Table  : LandRental
 Fields : LandRentalID, LandLordID, LandLordGroupID, Quarter, Year, Estimate

这里不要按字面意思理解1NF(第一范式)规则中的no repeating groups,因为这里的重复组现在都是来自参考表(即LandLord、LandLordGroup)的foreign keys。另外请注意,我现在在您的主表(即 LandRental)中添加了一个 Primary Key(LandRentalID)。

【讨论】:

  • 感谢你们的帮助。现在这个解决方案要简单得多。正如上面评论中提到的那样,我把事情复杂化了。
猜你喜欢
  • 2014-11-09
  • 1970-01-01
  • 2013-08-31
  • 2017-01-20
  • 2018-05-19
  • 1970-01-01
  • 2020-11-02
  • 1970-01-01
相关资源
最近更新 更多