中国广东省深圳市龙华新区民治街道溪山美地
518131
+8613113668890
+8675529812080<netkiller@msn.com>
文档始创于2012-11-16
版权 © 2010,2011,2012,2013 Netkiller(Neo Chan). All rights reserved.
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
|
|
$Date: 2013-04-10 15:03:49 +0800 (Wed,10 Apr 2013) $
我的系列文档
Netkiller Architect 手札 | Netkiller Developer 手札 | Netkiller PHP 手札 | Netkiller Python 手札 | Netkiller Testing 手札 | Netkiller Cryptography 手札 |
Netkiller Linux 手札 | Netkiller CentOS 手札 | Netkiller FreeBSD 手札 | Netkiller Security 手札 | Netkiller Version 手札 | Netkiller Web 手札 |
Netkiller Monitoring 手札 | Netkiller Storage 手札 | Netkiller Mail 手札 | Netkiller Shell 手札 | Netkiller Network 手札 | Netkiller Database 手札 |
Netkiller PostgreSQL 手札 | Netkiller MySQL 手札 | Netkiller NoSQL 手札 | Netkiller LDAP 手札 | Netkiller Cisco IOS 手札 | Netkiller H3C 手札 |
Netkiller Multimedia 手札 | Netkiller Docbook 手札 | Netkiller 开源软件 手札 |
Postgresql 实用实例参考
PostgreSQL 实用实例参考 (PDF)2004-07-20
PostgreSQL 实用实例参考 (BIG5 PDF)2004-07-20
PostgreSQL 实用实例参考 (HTML)2004-07-20
PostgreSQL 实用实例参考 (BIG5 HTML)2004-07-20
5.3.账户表/余额表/消费储蓄表此表适用于购物车等金钱来往账面等等。
-- table: account-- DROP table account;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))WITH ( OIDS=FALSE);ALTER table account OWNER TO dba;COMMENT ON ColUMN account.no IS '账号';COMMENT ON ColUMN account.balance IS '余额';-- Index: account_no_IDx-- DROP INDEX account_no_IDx;CREATE INDEX account_no_IDx ON account USING btree (no ColLATE pg_catalog."default");
账户结余计算
select acc.*,(select sum(balance)+acc.balance from account as ac where ac.ID < acc.ID) as profit from account as acc;test=# 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 | .00 | 2013-10-09 10:51:10 | 2 | 1000 | .60 | 2013-10-09 10:51:22 | .60 4 | 1000 | .80 | 2013-10-09 10:51:42 | .40 5 | 1000 | 0.00 | 2013-10-09 10:51:49 | 9.40 6 | 1000 | 0.00 | 2013-10-09 10:56:35 | 9.40 7 | 1000 | .45 | 2013-10-09 10:57:23 | 9.85 8 | 1000 | .50 | 2013-10-09 10:57:31 | 5.35 9 | 1000 | -.30 | 2013-10-09 10:59:28 | 0.05 10 | 1000 | -0.00 | 2013-10-09 10:59:44 | 0.05(9 rows)总结
以上是内存溢出为你收集整理的账户表/余额表/消费储蓄表全部内容,希望文章能够帮你解决账户表/余额表/消费储蓄表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)