문제

How can I make a query like:

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

But where freq sums values from a weight column instead of counting each row as 1?

I'm using MySQL 5.1.

도움이 되었습니까?

해결책

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

다른 팁

You want to use the Sum aggregate function to handle this.

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

Should do the trick!

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

use sum(weight) as freq in your select query

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top