我有一张transactions
表。
id account_id trx_date trx_type amount remarks
------ ---------- ---------- -------- ------ ---------
1 1 2017-12-10 DEPOSIT 500 test
2 1 2017-12-11 DEPOSIT 500 test
3 1 2017-12-12 DEPOSIT 6000 test
4 1 2017-12-13 WITHDRAW 300 test
5 1 2017-12-13 DEPOSIT 200 test
我想产生这种格式,但我无法弄清楚如何获取数据,如下所示。这里所有字段都与transactions
表相同。 op_bal
,cl_bal
是动态字段。
date trx_type op_bal amount cl_bal
2017-12-12 DEPOSIT 1000 6000 7000
2017-12-13 WITHDRAW 7000 300 6700
2017-12-13 DEPOSIT 6700 200 6900
答案 0 :(得分:0)
你好我已创建this sqlfiddle的给定输出,请检查答案
Ratings::where([['class_id', '=', $class_id], ['id', '=', $rating_id]])
->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);
和查询实现结果是
CREATE TABLE transactions (
id bigint(12) PRIMARY KEY auto_increment,
account_id bigint(12),
trx_date date,
trx_type enum('DEPOSIT','WITHDRAW'),
amount float(10,2),
remarks varchar(50)
);
INSERT INTO transactions (account_id, trx_date, trx_type, amount, remarks)
VALUES ('1','2017-12-10','DEPOSIT',500,'test'),
('1','2017-12-11','DEPOSIT',500,'test'),
('1','2017-12-12','DEPOSIT',6000,'test'),
('1','2017-12-13','WITHDRAW',300,'test'),
('1','2017-12-13','DEPOSIT',200,'test');
希望它对你有用。