• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sum of MySQL rows values and sum of values shouldn't be greater than php variable

#1
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:

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.
Reply

#2
@olegrain,

What code do you currently have in place to do a pull from the database? The query that your asking for is not complicated but are you asking for the code as well?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.