Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use sum to sum fields in Mybatis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report