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)
以下是全套:EXCEL财务报表(带公式)的下载全套EXCEL财务报表,包括适用于各行业的:凭证、总账、分类明细账(三拦和
有收入、支出、余额、应收款、应付款多栏)、科目账、T型账(丁字帐)、资产负债表(资产表)、利润表(损益表)、现金流量表、丁字帐(T型帐)、各行资产经营财务表格等等。带全套公式,只要把基本数据填写了,将自动生成汇总数据和相关数据,最大程度减少财务制表工作量。
您好,单个select语句实现MySQL查询统计次数的方法用处在哪里呢?用处太多了,比如一个成绩单,你要查询及格得人数与不及格的人数,怎么一次查询出来?MySQL查询统计次数简单的语句肯定是这样了:
select a.name,count_neg,count_plus from
(select count(id) as count_plus,name from score2 where score >=60 group by name) a,
(select count(id) as count_neg,name from score2 where score <=60 group by name) b
where a.name=b.name
即必须至少用2个语句。
今天刚好碰到发现mysql支持if,那就创造性的用if来实现吧:
select name, sum(if(score>=60,1,0)),sum(if(score<60,1,0)) from score2 group by name
单个select语句实现MySQL查询统计次数的方法简单吧。
原理就是大于60,就赋值为1,那么sum就是计数了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)