我有一个名为points的表,基于entires的不同值,我想对有效条目求和。
我有这个:
valid_entries | 代码 |
---|---|
1 | 768 |
2 | 1224 |
2 | 1224 |
1 | 512 |
1 | 512 |
首先用DISTINCT
过滤掉重复的行,然后聚合:
SELECT SUM(valid_entries) total
FROM (SELECT DISTINCT valid_entries, Codes FROM points WHERE participant_id='123') t;
请参阅演示