Name= the query in the record table? The value of the money added up
Sum with sum of function sums ()
Select SUM (Money) from record t where T.name =?
Other than that:
Count () to find the number of records
AVG () averaging
MySQL sum () Usage of SUM function
The syntax of the SUM function is:
Code to copy code as follows
SELECT SUM (expression)
From tables
WHERE predicates;
An expression can be a numeric field or a formula.
A simple example
For example, you may want to know that the total salary of the consolidated staff is more than USD, and its remuneration is 25,000/year
Code to copy code as follows
Select SUM (Salary) as "total salary"
From Employees
WHERE salary > 25000;
Used with the example using distinct
Code to copy code as follows
Select SUM (DISTINCT salary) as "total salary"
From Employees
WHERE salary > 25000;
Examples of working with formulas
The expression in the SUM function does not require a single field. You can also use a formula. For example, you may need net income for the business. Total revenue minus total net income calculated.
Code to copy code as follows
Select SUM (income-expenses) as "Net income"
From Gl_transactions;
You may also need to perform mathematical operations on the SUM function. For example, you might determine that the total Commission is 10% of the total sales.
Code to copy code as follows
Select SUM (Sales * 0.10) as "Commission"
From Order_Details;
With example using GROUP by
In some cases, you will be asked to use the SUM function of the first group.
For example, you can also use the SUM function to return the department name and total sales (related departments).
Code to copy code as follows
Select Department, SUM (sales) as "total sales"
From Order_Details
GROUP by department;
MySQL line multi-column sum sum () function2016-07-11 13:20 5492 People read comments (0) favorite reports Classification:MySQL (+)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The syntax of the SUM function is: SELECT SUM (expression) from tables WHERE predicates;
An expression can be a numeric field or a formula.
SELECT column 1+ column 2 + column 3 ... + column n as total from table
or select SUM (group_type+group_num_day+group_num_period+prize_pkg_id_owner) as total from Act_groupconfig;
MySQL sum () Usage of SUM function