select distinct userid, SUM(device)
from table
where userid != ''
group by userid, device;
userid | sum
---------+-----
a | 12
b | 1
c | 10
c | 78
why there is a duplicate userid without no sum calculated. All devices have integer values