【发布时间】:2020-08-30 23:54:02
【问题描述】:
我想获取活跃用户的字段总和和非活跃用户的字段总和。
id userId active total
1 1 1 10
2 1 1 5
3 1 0 30
4 1 0 20
期望结果为 activeTotal = 15 和 InactiveTotal = 50 的查询
选择 SUM(actUser.total) 作为 activeTotal,SUM(inActUser.total) 作为 inactiveTotal FROM 用户 actUser 加入用户 inActUser ON inActUser.id = inActUser.id WHERE (actUser.active = 1 AND actUser.userId = 1) OR (inActUser.active = 0 AND inActUser.userId= 1)
但我没有得到预期的结果....我得到的非活跃用户数与非活跃用户数相同。
【问题讨论】: