0

如何进行如下查询:

select myvalue, count() as freq from mytable group by myvalue;

但是在哪里对列中的freq值求和weight而不是将每一行都计为 1?

我正在使用 MySQL 5.1。

4

4 回答 4

3

您想使用Sum聚合函数来处理此问题。

SELECT MyValue, Sum(weight) AS Total
FROM mytable
GROUP BY myvalue;

应该做的伎俩!

于 2010-09-29T16:41:34.663 回答
2
select myvalue, sum(weight) as freq from mytable group by myvalue;
于 2010-09-29T16:41:40.083 回答
2
select myvalue, SUM(weight) as freq from mytable group by myvalue;
于 2010-09-29T16:41:51.550 回答
1

sum(weight) as freq在您的选择查询中使用

于 2010-09-29T16:42:31.253 回答