SQL:怎样用GROUP BY加权计数?
-
26-09-2019 - |
题
我怎样才能做一个查询,如:
select myvalue, count() as freq from mytable group by myvalue;
但是,在freq
总和值从weight
柱代替计数每一行作为1?
我使用的MySQL 5.1。
解决方案
select myvalue, sum(weight) as freq from mytable group by myvalue;
其他提示
select myvalue, SUM(weight) as freq from mytable group by myvalue;
使用sum(weight) as freq
在您选择查询
不隶属于 StackOverflow