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 the sum function of mysql

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly tells you how to use the sum function of mysql, related technical terms you can check online or find some related books to supplement, here is not involved, we will go straight to the topic, I hope the sum function of mysql How to use this article can bring you some practical help.

SUM(DISTINCT expression)

How does SUM() function work?

if that SUM function is use in a SELECT statement that returns no match rows, the SUM function returns NULL instead of 0. The DISTINCT operator allows different values in a set to be computed. The SUM function ignores NULL values in calculations.

MySQL SUM() function example

Let's look at the orderdetails table in the sample database (yiibaidb).

You can use the SUM() function to calculate the total amount for order number 10100, as shown in the following query:

SELECT FORMAT(SUM(quantityOrdered * priceEach),2) total FROM orderdetails WHERE orderNumber = 10100;

Executing the query above yields the following results

mysql> SELECT FORMAT(SUM(quantityOrdered * priceEach),2) total FROM orderdetails WHERE orderNumber = 10100;

+-----------+

| total |

+-----------+

| 10,223.83 |

+-----------+

1 row in set

SQL

Note that the FORMAT() function is used to format the return value of the SUM() function.

How to use the sum function of mysql will be mentioned to you first. For other related issues, you can continue to pay attention to our industry information if you want to know. Our section content captures some industry news and expertise to share with you every day.

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: 257

*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

Database

Wechat

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

12
Report