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

时间:2010-02-17 12:51:07

标签: mysql

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

5 个答案:

答案 0 :(得分:15)

SELECT 
    SUM(your_column) AS Total
FROM
    your_table;

......或者这是一个技巧问题吗? :)

答案 1 :(得分:13)

Here是由聚合

组成的MySQL内置函数列表
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

我相信你想要SUM()

答案 2 :(得分:3)

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

答案 3 :(得分:0)

SELECT SUM(col)FROM table

答案 4 :(得分:-1)

SELECT SUM(`subquery`.`qty`) FROM (
SELECT `qty` FROM `table1` WHERE [ your query conditions ]
) AS `subquery`