如何显示不同的值和总和

How to display distinct Value and total sum

我有表 1:

现在我想从类型列中获取值,计算唯一的 PiD,并显示类型值的总和。结果应该 return 低于输出:

对于 Type= "ABC" 我有 4 个唯一的 Pid,sum(Value) = (10+20+30+40+10+50+60+20) 是 240

如何编写正确的SQL查询?

select l2, fq, type, count(distinct pid), sum(value)
from your_table
group by l2, fq, type

select L2,FQ,Type, count(distinct pid),sum(Value) from table1 group by 1,2,3;