to: teddy_huang(生活多美好,睡觉) 我先也是这样做的,但我发觉后来数据不准确,我想求得所有用户的某一种状态的和 比如0001有两条记录 ID | USERID | MSTATES |NSTATES | 1 0001 0 1 2 0001 0 0如果用select count(*) from table where (mstates=0 or nstates=0) and userid='0001' group by userid 还求的话,它只有2条,但实际它有三条才对
select id,sum(decode(mstates,1,1,0)), sum(decode(nstates,1,1,0)) from table group by userid
比如group by userid,MSTATES
我先也是这样做的,但我发觉后来数据不准确,我想求得所有用户的某一种状态的和
比如0001有两条记录
ID | USERID | MSTATES |NSTATES |
1 0001 0 1
2 0001 0 0如果用select count(*) from table
where (mstates=0 or nstates=0) and userid='0001'
group by userid 还求的话,它只有2条,但实际它有三条才对
from table
group by userid
多谢你了,我还知道oracle还有decode这么一个函数