mysql group by field,忽略特定列中的重复项

时间:2015-12-01 00:51:11

标签: mysql

我有一张记录产品点击次数的表格。例如:

productId

我需要按productId分组,但只计算一个ipv4 - productId COUNT(*) SUM(flag) 100 2 2 101 1 1 对。我需要忽略来自同一用户的产品的任何重复点击。

预期结果:

public interface Implementable {}

@Deserializable(Implementable.class)
public class ImplementableFactory {
    public static Implementable getImplementable() {
        return new Impl();
    }
    private class Impl implements Implementable {}
}

我如何构建查询?

1 个答案:

答案 0 :(得分:0)

这样的事情:

select productid, count(distinct ipv4), count(distinct ipv4, flag)
from foo
group by productId

检查sqlfiddle:http://sqlfiddle.com/#!9/ac487/1