Q:

Running sums for current month with cap on cumulative running total

I want to create a report which contains the total transaction amounts for a particular month, but only have them appear if the total amount for that account is less than a particular cap for that account. For any fringe transactions which would pierce the cap, I would only show the portion of the amount below the cap. Below is an example.
This would have to be compatible with version 5.6.24
CREATE TEMPORARY TABLE Example(
   ID int,
   Date DATE,
   AMT FLOAT(8,2)
);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (1, '20190101', 1000);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (1, '20190123', 1000);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (1, '20190201', 1000);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (2, '20180202', 2000);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (2, '20190115', 1500);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (2, '20190501', 1000);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (2, '20190502', 750);
INSERT INTO Example(ID, Date, AMT) 
            VALUES (2, '20190505', 800);

The data is of the following format and assume I have a cumulative cap of 5000 per ID.
ID     |    Date     |    AMT     |
 1     |  1/1/2019   |   1000     |
 1     |  1/23/2019  |   1000     |
 1     |  2/1/2019   |   1000     |
 2     |  2/2/2018   |   2000     |
 2     |  1/15/2019  |   1500     |
 2     |  5/1/2019   |   1000     |
 2     |  5/2/2019   |   750      |
 2     |  5/5/2019   |   800      |

As of 1/31/2019, I expect to see the following result returned, which is pretty trivial:
ID     |    Date     |  CM_AMT    |  RUNNING
 1     |  1/1/2019   |   1000     |  1000
 1     |  1/23/2019  |   1000     |  2000
 2     |  1/15/2019  |   1500     |  3500

However, as of 5/31/2019, I expect to see:
ID     |    Date     |  CM_AMT    |   RUNNING
 2     |  5/1/2019   |   1000     |   4500
 2     |  5/2/2019   |   500      |   5000

Because there are no transactions for ID 1, no records should appear.
For ID 2, we have the running total from the beginning of inception. Any records after the cap has been met are dropped, hence no 5/5/2019 record. And we only record the part of a transaction before it pierces the total, ie: the 5/2/2019 record is 500 instead of 750

A:

If you are runing MySQL 8.0, you can do a window sum and filter by that. Then, you can use least() ajust the amount on the last record per id (if necessary).
select 
    id, 
    date, 
    least(amt, amt - running + 5000) amt,
    least(running, 5000) running
from (
    select 
        t.*,
        sum(amt) over(partition by id order by date) running
    from Example t
) t
where running - amt <= 5000
order by id, date

Demo on DB Fiddle:

id | date       |     amt | running
-: | :--------- | ------: | ------:
 1 | 2019-01-01 | 1000.00 | 1000.00
 1 | 2019-01-23 | 1000.00 | 2000.00
 1 | 2019-02-01 | 1000.00 | 3000.00
 2 | 2018-02-02 | 2000.00 | 2000.00
 2 | 2019-01-15 | 1500.00 | 3500.00
 2 | 2019-05-01 | 1000.00 | 4500.00
 2 | 2019-05-02 |  500.00 | 5000.00

In earlier versions of MySQL, you can emulate the window sum with a self-join and aggregation (or correlated subquery would also do the job):
select 
    id, 
    date, 
    least(amt, amt - running + 5000) amt,
    least(running, 5000) running
from (
    select t.id, t.date, t.amt, sum(t1.amt) running
    from Example t
    inner join Example t1 on t1.id = t.id and t1.date <= t.date
    group by t.id, t.date, t.amt
) x
where running - amt <= 5000
order by id, date

Demo on MySQL 5.6 DB Fiddle

