我有以下表格:
我该怎么处理帐单?


到目前为止:
发布于 2015-07-13 21:59:58
如果我是你,我会确保分离所有的数据。这将被完全控制在数据库中,还是会有一个应用程序?如果是应用程序,我将为使用应用程序的人员提供一个用户表和权限表。我会为你的客户做一个单独的顾客桌。我同意可用性表,但如果您使用的是基于价格的系统,我将单独存储。为了结账,我会摆几张桌子。我会有一个付款类型表和一个有到期日期的交易表。我也喜欢入住和退房的想法。
发布于 2015-07-14 12:57:59
我做了一个可能对你有帮助的结构。
room状态,您可以知道哪个是房间的实际状态。您应该尝试在要在查询中筛选的字段中添加索引。
CREATE TABLE `room` (
`id` int(6) NOT NULL,
`roomName` varchar(75) DEFAULT NULL,
`date` datetime DEFAULT NULL,
`status` int(2) DEFAULT NULL,
`othersfields` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `room_status` (
`idroom_status` int(2) NOT NULL,
`sName` varchar(45) DEFAULT NULL,
PRIMARY KEY (`idroom_status`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `transaction` (
`id` int(6) NOT NULL,
`room_id` int(6) DEFAULT NULL,
`check_in` datetime DEFAULT NULL,
`check_out` datetime DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`othersfields` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`fName` varchar(45) DEFAULT NULL,
`lName` varchar(45) DEFAULT NULL,
`pwd` varchar(45) DEFAULT NULL,
`rol` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;mysql> SELECT * FROM test.room;
+----+----------+---------------------+--------+--------------+
| id | roomName | date | status | othersfields |
+----+----------+---------------------+--------+--------------+
| 1 | Suit | 2015-07-13 00:00:00 | 1 | NULL |
| 2 | Normal | NULL | 2 | NULL |
| 3 | Other | NULL | 1 | NULL |
+----+----------+---------------------+--------+--------------+
3 rows in set (0.00 sec)
mysql> select * from test.room_status;
+---------------+-------------+
| idroom_status | sName |
+---------------+-------------+
| 1 | Open |
| 2 | Closed |
| 3 | Maintenance |
+---------------+-------------+
3 rows in set (0.00 sec)
mysql> select * from test.user;
+----+-------+-------+------------+------+
| id | fName | lName | pwd | rol |
+----+-------+-------+------------+------+
| 1 | oNare | Test | 123ka21312 | NULL |
+----+-------+-------+------------+------+
1 row in set (0.00 sec)
mysql> select * from test.transaction;
+----+---------+---------------------+---------------------+---------+--------------+
| id | room_id | check_in | check_out | user_id | othersfields |
+----+---------+---------------------+---------------------+---------+--------------+
| 1 | 1 | 2015-07-01 00:00:00 | 2015-07-02 00:00:00 | 1 | NULL |
| 2 | 1 | 2015-07-03 00:00:00 | 2015-07-05 00:00:00 | 1 | NULL |
| 3 | 2 | 2015-07-03 00:00:00 | 2015-07-04 00:00:00 | 1 | NULL |
| 4 | 1 | 2015-07-13 00:00:00 | NULL | 1 | NULL |
| 5 | 2 | 2015-07-09 00:00:00 | 2015-07-13 00:00:00 | 1 | NULL |
+----+---------+---------------------+---------------------+---------+--------------+
5 rows in set (0.00 sec)
mysql> mysql> SELECT
-> r.id AS idRoom,
-> r.roomName,
-> rs.sName as Status,
-> t.check_in,
-> t.check_out
-> FROM test.transaction AS t
-> JOIN test.room AS r ON (t.room_id=r.id)
-> JOIN test.room_status AS rs ON (rs.idroom_status=r.status)
-> JOIN test.user AS u ON (t.user_id=u.id);
+--------+----------+--------+---------------------+---------------------+
| idRoom | roomName | Status | check_in | check_out |
+--------+----------+--------+---------------------+---------------------+
| 1 | Suit | Open | 2015-07-01 00:00:00 | 2015-07-02 00:00:00 |
| 1 | Suit | Open | 2015-07-03 00:00:00 | 2015-07-05 00:00:00 |
| 1 | Suit | Open | 2015-07-13 00:00:00 | NULL |
| 2 | Normal | Closed | 2015-07-03 00:00:00 | 2015-07-04 00:00:00 |
| 2 | Normal | Closed | 2015-07-09 00:00:00 | 2015-07-13 00:00:00 |
+--------+----------+--------+---------------------+---------------------+
5 rows in set (0.00 sec)
mysql> https://dba.stackexchange.com/questions/106818
复制相似问题