I have a table named wallet
, which is like this:
// wallet
+----+----------+----------+------------+
| id | user_id | amount | created_at |
+----+----------+----------+------------+
| 1 | 5 | 1000 | 2022-05-20 | -- 1000
| 2 | 5 | 500 | 2022-05-20 | -- 1500
| 3 | 5 | -1000 | 2022-05-21 | -- 500 <-- this
| 4 | 5 | 4000 | 2022-05-23 | -- 4500
| 5 | 5 | -2000 | 2022-05-23 | -- 2500
| 6 | 5 | 1000 | 2022-05-24 | -- 3500
+----+----------+----------+------------+
As you can see, (after all deposits and withdrawals), sum(amount)
is 500
at the lower point (minimum calculated amount) in the period which is happened at 2022-05-21
. So, selecting this row is the expected result:
| 3 | 5 | -1000 | 2022-05-21 |
Any idea how can I get that?