CREATE TABLE account
(
id integer NOT NULL DEFAULT nextval('trade_id_seq'::regclass),
no character varying(10) NOT NULL, -- 账号
balance money NOT NULL DEFAULT 0.00, -- 余额
datetime timestamp without time zone NOT NULL DEFAULT (now())::timestamp(0) without time zone,
CONSTRAINT account_pkey PRIMARY KEY (id)
)
通过每次的余额变化就知道每次消费后的余额情况
select acc.*, (select sum(balance)+acc.balance from account as ac where ac.id <acc.id) as profit from account as acc
id | no | balance | datetime | profit
----+------+----------+---------------------+---------
1 | 1000 |$0.00 | 2013-10-09 10:51:10 |
2 | 1000 | $12.60 | 2013-10-09 10:51:22 | $12.60
4 | 1000 | $16.80 | 2013-10-09 10:51:42 | $29.40
5 | 1000 | $100.00 | 2013-10-09 10:51:49 | $129.40
6 | 1000 | $200.00 | 2013-10-09 10:56:35 | $329.40
7 | 1000 | $50.45 | 2013-10-09 10:57:23 | $379.85
8 | 1000 | $75.50 | 2013-10-09 10:57:31 | $455.35
9 | 1000 | -$55.30 | 2013-10-09 10:59:28 | $400.05
10 | 1000 | -$200.00 | 2013-10-09 10:59:44 | $200.05
(9 rows)
会员基本信息一个表 会员ID做主键体检记录一个表 这里面要有一列会员的ID
服务人员信息一个表 服务人员ID做主键
评价记录一个表 这里面要有会员id 和 服务人员Id
外键不用在数据库里设置 我觉得在程序里面几个表联合查询就行
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)