获取sqlite中的重复次数

时间:2019-09-30 19:35:56

标签: sql database sqlite

此表的操作方式
image1
获取此表(对等方应相同,即,其中peer =程序中指定的对等方)
动作0为减,动作1为加
enter image description here

2 个答案:

答案 0 :(得分:1)

您似乎想要一个简单的汇总:

select whom, sum(action) as plus, sum(1 - action)  as minus
from t
group by whom;

答案 1 :(得分:1)

有条件聚合:

select
  whom,
  sum(action = 1) plus,
  sum(action = 0) minus
from tablename
where peer = ?
group by whom