Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use sum to sum fields in Mybatis

Shulou Source: shulou.com Published: 2022-06-01 19:21:39 10月04日 Update

This article mainly explains "how to use sum to sum fields in Mybatis". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use sum to sum fields in Mybatis".

Use sum to sum fields

The following sql is used to calculate the total revenue of users:

Select sum (income) as totalIncome from income_log where uid = # {uid,jdbcType=BIGINT}

The type of summation field returned needs to be set to BigDecimal:

Public class UserIncomeEntity {private BigDecimal totalIncome;} avoid Mybatis sum summation return nullSELEC SUM (ORDER_MONEY) FROM gm_order WHERE ADD_UID = # {userCode}

If there is no result, the above method will return null. In fact, we hope to return the case of 0.00.

SELECT COALESCE (SUM (ORDER_MONEY), 0) FROM gm_order WHERE ADD_UID = # {userCode} Thank you for your reading, this is the content of "how to use sum to sum fields in Mybatis". After the study of this article, I believe you have a deeper understanding of how to use sum to sum fields in Mybatis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Fields learning content situation writing as above that is ideas summation benefits articles more users knowledge knowledge points articles types results follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information NVidia Shulou Tech Info Xiaomi