我在查询中有问题。我使用 posgresql。我需要得到总行,但条件是“分组依据”
table qwe
----------------------------
TIPE | VAL
----------------------------
1 | 2
2 | 3
2 | 1
2 | 4
3 | 1
3 | 3
我需要的结果是
-------------------------
TIPE | VAL | TOTAL TIPE
-------------------------
1 | 2 | 3
2 | 8 | 3
3 | 4 | 3
到目前为止我尝试过的查询
select tipe, sum(val), count(tipe) "total tipe"
from qwe group by tipe order by tipe
-------------------------
TIPE | VAL | TOTAL TIPE
-------------------------
1 | 2 | 1
2 | 8 | 3
3 | 4 | 2