07-28-2020, 02:03 AM

Hello! I use Codeigniter 3.1.11 and have a php variable $maximum_amount with value of '0.50000000'.

In my MySQL database I have a table called 'orders' with a rows for example:

I need to select rows with SUM of 'amount' but the SUM of 'amount' shouldn't be be greater than variable $maximum_amount. I need to use order ASC by 'created_time' and limit '100'. I know what I need to use Cumulative Sum, but I don't know how to do it with Codeigniter. Please, help to solve this.

In my MySQL database I have a table called 'orders' with a rows for example:

Code:

`#table orders`

+----------+-----------+--------------+---------------------+

| OrderID | UserID | amount | created_time |

+----------+-----------+--------------+---------------------+

| a1bh | htl57 | 0.10000000 | 2020-07-27 08:23:11 |

| 2c3f | 34gh7 | 0.30000000 | 2020-07-27 08:24:49 |

| 4d5s | lkr37 | 0.20000000 | 2020-07-27 08:29:03 |

| 5e6k | jkw68 | 0.50000000 | 2020-07-27 08:30:04 |

+----------+-----------+--------------+---------------------+

I need to select rows with SUM of 'amount' but the SUM of 'amount' shouldn't be be greater than variable $maximum_amount. I need to use order ASC by 'created_time' and limit '100'. I know what I need to use Cumulative Sum, but I don't know how to do it with Codeigniter. Please, help to solve this.