Get the App
SLTechnology News&Howtos  ›  Database  › 

How MySQL generally implements the sql writing method of phase accumulation (with a code example)

Shulou Source: shulou.com Published: 2022-06-01 20:48:38 10月12日 Update

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)

Tags: Writing requirements code examples stages balance content consumption different straightforward following professional books people value redundancy charts scenarios fields that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS MariaDB Shulou Information Docker