如何构建db表来存储范围,如0; 20; 40; 60; 80或0; 50; 100; 150; 200; 250; ...等等

时间:2013-03-19 10:38:44

标签: oracle database-design relational-database database-schema

我想将下面的范围存储在一个表中,template01中的项目数是6,第二个是4.我们如何构造表来存储这些信息。将这些值显示为逗号分隔或为每个范围值指定一列将是我的最后一个选项。你能帮忙知道如何构建表/表来存储下面说的信息。

Template01      0      10       20         30      40       50
Template02      0      50      100        150
Template03      0     100      200        300     400      500      600 

基本上,我想将这些范围存储为模板,并在以后使用它来说明行李重量是否为0-10,每公斤花费5美元,如果10到20,则每公斤花费4.8美元等< / p>

这是模板的使用方式,

Domain: XYZ
Template01      0      10       20         30      40       50
Increment01%   125%    120%      115%       110%    105%    100%

Domain: ABC, am using or picking the same template 'Template01' but Increment% 
will be different for different domain, hence

Template01      0      10       20         30      40       50
Increment02%   150%    140%      130%       120%    110%    100%

想法是,我想存储减肥模板,之后我想与不同的增量%相关联。因此,当用户选择权重中断模板时,可以显示适用于该模板的所有增量%值,供用户选择一个。

Template01      0      10       20         30      40       50
Increment01%   125%    120%      115%       110%    105%    100%  [Choice 1]
Increment02%   150%    140%      130%       120%    110%    100%  [Choice 2]

2 个答案:

答案 0 :(得分:5)

标准方法是:

Template_Name  Weight_From  Weight_To  Price
-------------  -----------  ---------  -----
Template01     0            10         5
Template01     10           20         4.8
...
Template01     40           50         ...
Template01     50           (null)     ...
Template02     0            50         ...
...
Template03     500          600        ...
Template03     600          (null)     ...

答案 1 :(得分:1)

对于规范化架构,您需要为模板,增量,模板权重和增量因子提供表格。

 create table luggage_weight_template (
   luggage_weight_template_id number primary key,
   template_name varchar2(100) unique);


 create table luggage_increment (
   luggage_increment_id number primary key,
   increment_name varchar2(100), 
   luggage_weight_template_id  references luggage_weight_template(luggage_weight_template_id)); 


 create table template_weight (
   template_weight_id number primary key,
   luggage_weight_template_id references luggage_weight_template(luggage_weight_template_id),
   weight_from  number not null);


 create table increment_factor (
   increment_factor number primary key,
   increment_id references luggage_increment(luggage_increment_id),
   template_weight_id references template_weight(template_weight_id));