简体   繁体   中英

How to select sum of column in result of select?

如何在select的结果中选择列的总和?

SELECT 
    SUM(your_column) AS Total
FROM
    your_table;

... or is this a trick question? :)

Here is a list of MySQL built in functions for the group by aggregate

 AVG() Return the average value of the argument BIT_AND() Return bitwise and BIT_OR() Return bitwise or BIT_XOR()(v4.1.1) Return bitwise xor COUNT(DISTINCT) Return the count of a number of different values COUNT() Return a count of the number of rows returned GROUP_CONCAT()(v4.1) Return a concatenated string MAX() Return the maximum value MIN() Return the minimum value STD() Return the population standard deviation STDDEV_POP()(v5.0.3) Return the population standard deviation STDDEV_SAMP()(v5.0.3) Return the sample standard deviation STDDEV() Return the population standard deviation SUM() Return the sum VAR_POP()(v5.0.3) Return the population standard variance VAR_SAMP()(v5.0.3) Return the sample variance VARIANCE()(v4.1) Return the population standard variance 

I believe that you want SUM()

SELECT SUM(sales) as "Revenue" FROM details;

SELECT SUM(col)FROM表

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM