我设计了移动电话和关税的数据库表。
它应该支持多个移动网络、销售类型和相关联属网络。
积分(针对运营商)因所选电话、资费、网络和销售类型而异。
示例价格计划:
T-Mobile:消费者升级
- 三星Galaxy S3
- 关税:Super One(每月费用:12.00 美元)
- 此销售会员与“零售商一号”
- 总分:3.3
T-Mobile :消费者新连接
- 三星Galaxy S3
- 关税:Super One(每月费用:35.00 美元)
- 此销售附属于“零售商二”
- 总分:7.3
AT&T:“Sim Only Deal”(无电话)
- 关税:X-Deal 2(每月费用:18.00 美元)
- 此销售会员与“零售商一号”
- 总分:10.0
请参阅下面的表格设计,这是应该怎么做的?或者如何改进?
数据库设计:
CREATE TABLE IF NOT EXISTS `affiliate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `affiliate` (`id`, `name`) VALUES
(1, 'Retailer One'),
(2, 'Retailer Two');
CREATE TABLE IF NOT EXISTS `network` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `network` (`id`, `name`) VALUES
(1, 'T-Mobile'),
(2, 'AT&T');
CREATE TABLE IF NOT EXISTS `network_saletype` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`network_id` int(11) NOT NULL,
`saletype_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `network_saletype` (`id`, `network_id`, `saletype_id`) VALUES
(1, 1, 1),
(2, 2, 3);
CREATE TABLE IF NOT EXISTS `phone` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `phone` (`id`, `name`, `description`) VALUES
(1, 'Samsung Galaxy S3', ' Quad-core, NFC, AMOLED'),
(2, 'Apple iPhone 4S', 'A5 chip, 8MP camera, Siri voice');
CREATE TABLE IF NOT EXISTS `phone_points` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`phone_id` int(11) NOT NULL,
`tarrif_id` int(11) NOT NULL,
`affilicate_id` int(11) NOT NULL,
`point` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `phone_points` (`id`, `phone_id`, `tarrif_id`, `affilicate_id`, `point`) VALUES
(1, 1, 1, 1, 3.3),
(2, 1, 2, 2, 7.3);
CREATE TABLE IF NOT EXISTS `saletype` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
INSERT INTO `saletype` (`id`, `name`) VALUES
(1, 'Consumer Upgrade'),
(2, 'Consumer New Connection'),
(3, 'Sim-Only Deal');
CREATE TABLE IF NOT EXISTS `tariff_point` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tarrif_id` int(11) NOT NULL,
`affilicate_id` int(11) NOT NULL,
`point` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
INSERT INTO `tariff_point` (`id`, `tarrif_id`, `affilicate_id`, `point`) VALUES
(3, 3, 1, 10);
CREATE TABLE IF NOT EXISTS `tarrif` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`network_saletype_id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`tariff_duration` int(11) NOT NULL,
`monthly_cost` decimal(6,2) NOT NULL,
`description` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
INSERT INTO `tarrif` (`id`, `network_saletype_id`, `name`, `tariff_duration`, `monthly_cost`, `description`) VALUES
(1, 1, 'Super One', 12, '12.00', '200 Mins, 400 Texts, 500MB Internet'),
(2, 1, 'Super One', 12, '35.00', '200 Mins, 400 Texts, 500MB Internet'),
(3, 2, 'X-Deal Two', 12, '18.00', '');
结果
mysql> select * from network;
+----+----------+
| id | name |
+----+----------+
| 1 | T-Mobile |
| 2 | AT&T |
+----+----------+
mysql> select * from affiliate;
+----+--------------+
| id | name |
+----+--------------+
| 1 | Retailer One |
| 2 | Retailer Two |
+----+--------------+
mysql> select * from saletype;
+----+-------------------------+
| id | name |
+----+-------------------------+
| 1 | Consumer Upgrade |
| 2 | Consumer New Connection |
| 3 | Sim-Only Deal |
+----+-------------------------+
mysql> select * from network_saletype;
+----+------------+-------------+
| id | network_id | saletype_id |
+----+------------+-------------+
| 1 | 1 | 1 |
| 2 | 2 | 3 |
+----+------------+-------------+
mysql> select * from tarrif;
+----+---------------------+------------+-----------------+--------------+-------------------------------------+
| id | network_saletype_id | name | tariff_duration | monthly_cost | description |
+----+---------------------+------------+-----------------+--------------+-------------------------------------+
| 1 | 1 | Super One | 12 | 12.00 | 200 Mins, 400 Texts, 500MB Internet |
| 2 | 1 | Super One | 12 | 35.00 | 200 Mins, 400 Texts, 500MB Internet |
| 3 | 2 | X-Deal Two | 12 | 18.00 | |
+----+---------------------+------------+-----------------+--------------+-------------------------------------+
mysql> select * from tariff_point;
+----+-----------+---------------+-------+
| id | tarrif_id | affilicate_id | point |
+----+-----------+---------------+-------+
| 3 | 3 | 1 | 10 |
+----+-----------+---------------+-------+
mysql> select * from phone;
+----+-------------------+---------------------------------+
| id | name | description |
+----+-------------------+---------------------------------+
| 1 | Samsung Galaxy S3 | Quad-core, NFC, AMOLED |
| 2 | Apple iPhone 4S | A5 chip, 8MP camera, Siri voice |
+----+-------------------+---------------------------------+
mysql> select * from phone_points;
+----+----------+-----------+---------------+-------+
| id | phone_id | tarrif_id | affilicate_id | point |
+----+----------+-----------+---------------+-------+
| 1 | 1 | 1 | 1 | 3.3 |
| 2 | 1 | 2 | 2 | 7.3 |
+----+----------+-----------+---------------+-------+
编辑:我的问题是电话、收费、网络和销售类型之间的关系设计可以吗?基本上运营商可以选择一个零售商,然后选择移动网络..然后选择什么类型的销售(例如:消费者升级),然后选择具有相关关税的手机。根据他们选择的关税和/或电话 - 运营商获得积分。