mysql消费明细怎么做 mysql查询消费总额

mysql 帐号余额和消费记录表设计?余额可以单独用一个余额记录表mysql消费明细怎么做,这样如果要查询每次消费记录mysql消费明细怎么做的时候,也能查出来每次消费后还有多少余额 。余额记录表里面主要是三个字段mysql消费明细怎么做:用户账号、每次消费后的余额、时间点 。
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, -- 余额
【mysql消费明细怎么做 mysql查询消费总额】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.idacc.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)
mysql有两张表,一个user表,一个消费表,用left join怎样查询用户近一个月的消费记录from user表 a
left join 消费表 b on a.username=b.username
// left join是左关联,关键字会从左表那里返回所有的行,即使在右表中没有匹配的行
PHP MYSQL循环输出一个月的消费记录,并统计每一天的支出与收入总合//统计当天支出总额
$sql_out="select sum(cash) as cashout from my_money where time$dayend and time$daybegin and type=1 group by FROM_UNIXTIME(time,'%y-%m-%d')";
//统计当天收入总额
$sql_in="select sum(cash) as cashin from my_money where time$dayend and time$daybegin and type=2 group by FROM_UNIXTIME(time,'%y-%m-%d')";
mysql消费明细怎么做的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于mysql查询消费总额、mysql消费明细怎么做的信息别忘了在本站进行查找喔 。

    推荐阅读