select sum(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='inbox' then 1 else 0 end) count1,
sum(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='sendbox' then 1 else 0 end) count2,
sum(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='trashbox' then 1 else 0 end) count3,
sum(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='inbox' then 1 else 0 end) count4
sum(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='sendbox' then 1 else 0 end) count5
sum(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='trashbox' then 1 else 0 end) count6
from mailinfo ;
sum(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='sendbox' then 1 else 0 end) count2,
sum(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='trashbox' then 1 else 0 end) count3,
sum(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='inbox' then 1 else 0 end) count4
sum(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='sendbox' then 1 else 0 end) count5
sum(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='trashbox' then 1 else 0 end) count6
from mailinfo ;
sum(case when maillocation='inbox' then 1 else 0 end) 收件箱,
sum(case when maillocation='sendbox' then 1 else 0 end) 发件箱,
sum(case when maillocation='trashbox' then 1 else 0 end) 垃圾箱
from mailinfo group by userindex ;
用楼上的方法就好了,它同样利用了索引userindex 。