给我返回用户进行的最新交易

时间:2019-05-05 11:12:00

标签: java mysql database swing

我想通过使用clientid获取该帐号的最新交易。我没有合适的解决方案。

我已经尝试选择* From transactions,其中accountno =“ A6B55” ORDER BY clientids desc LIMIT 1;

clientids  date   time   cardno  accountno   transactiontype   currbalance
---------------------------------------------------------------------------
1       2019-02-26 5:18AM  865505   A6B55     withdraw         20,000

2       2019-02-26 6:15PM  865505  A6B55     deposit            30,000

3       2019-02-26 9:10PM  78805   6979A     deposit           10,0000

我希望能给我该帐户进行的最新交易。例如,您可以在我的表帐户上看到,A6B55当天没有进行过两次交易,该帐户的clientid为1和2,我只想获取2号clientid以及日期,时间,卡号,交易类型和currbalance。 谢谢!

1 个答案:

答案 0 :(得分:0)

请尝试此解决方案;

create table transactions (clientid INT PRIMARY KEY, date DATE, time TIME, CardNo INT, accountno VARCHAR(100), Transactiontype VARCHAR(20), curbalance float);

mysql> desc transactions;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| clientid        | int(11)      | NO   | PRI | NULL    |       |
| date            | date         | YES  |     | NULL    |       |
| time            | time         | YES  |     | NULL    |       |
| CardNo          | int(11)      | YES  |     | NULL    |       |
| accountno       | varchar(100) | YES  |     | NULL    |       |
| Transactiontype | varchar(20)  | YES  |     | NULL    |       |
| curbalance      | float        | YES  |     | NULL    |       |
+-----------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> insert into transactions values(1, '2019-02-26', '05:18:00', 865505, 'A6B55', 'withdraw', 20000);
mysql> insert into transactions values(2, '2019-02-26', '18:15:00', 865505, 'A6B55', 'deposit', 30000);
mysql> insert into transactions values(3, '2019-02-26', '21:10:00', 78805, '6979A', 'deposit', 100000);

mysql> select * from transactions;
+----------+------------+----------+--------+-----------+-----------------+------------+
| clientid | date       | time     | CardNo | accountno | Transactiontype | curbalance |
+----------+------------+----------+--------+-----------+-----------------+------------+
|        1 | 2019-02-26 | 05:18:00 | 865505 | A6B55     | withdraw        |      20000 |
|        2 | 2019-02-26 | 18:15:00 | 865505 | A6B55     | deposit         |      30000 |
|        3 | 2019-02-26 | 21:10:00 |  78805 | 6979A     | deposit         |     100000 |
+----------+------------+----------+--------+-----------+-----------------+------------+

mysql> select * from transactions where accountno = 'A6B55' ORDER BY time desc LIMIT 1;
+----------+------------+----------+--------+-----------+-----------------+------------+
| clientid | date       | time     | CardNo | accountno | Transactiontype | curbalance |
+----------+------------+----------+--------+-----------+-----------------+------------+
|        2 | 2019-02-26 | 18:15:00 | 865505 | A6B55     | deposit         |      30000 |
+----------+------------+----------+--------+-----------+-----------------+------------+

祝您有美好的一天:)干杯...