How MySQL generally implements the sql writing method of phase accumulation (with a code example)
The following content mainly brings you MySQL is generally how to achieve stage accumulation of sql writing (to code examples), the knowledge mentioned, slightly different from books, are summed up by professional and technical personnel in the process of contact with users, with a certain experience sharing value, hoping to bring help to the majority of readers.
Recently, there is a demand: count the balance after daily recharge / consumption, which is actually very simple, just calculate the balance after each recharge / consumption, and then save it. But for this kind of requirement, one sql can do it, and there is no need to do redundant fields.
The chart shows that this scene may be more straightforward.
The desired result
Write method 1:
Select T. price, (select sum (price) from t_charge temp where temp.date)