求高效率统计方法

xiaoxi99cspy 2003-10-15 08:59:46
表结构如下:
mailId(邮件id) userId(用户id) maillocation(邮件位置,有收件箱inbox,发件箱sendbox,垃圾箱trashbox三种) mailsize(邮件大小)
现在要分别统计每个用户的inbox,sendbox,trashbox三个邮箱的邮件数和大小,怎么写效率高啊

我想扫描一变纪录统计出,用case语句,但不知为何不对
select count(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='inbox' then 1 else 0 end) count1,
count(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='sendbox' then 1 else 0 end) count2,
count(case when userindex='ca8USERID00000002943f262f0600000041' and maillocation='trashbox' then 1 else 0 end) count3,
count(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='inbox' then 1 else 0 end) count4
count(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='sendbox' then 1 else 0 end) count5
count(case when userindex='caUSERID00000003333f262f0600000036' and maillocation='trashbox' then 1 else 0 end) count6
from mailinfo ;

得到的结果是总的纪录个数,并不是单个的纪录,我用的oracle9i


还有邮件总的大小,各位大虾,能不能给出效率高点的方法
...全文
61 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxi99cspy 2003-10-15
  • 打赏
  • 举报
回复
大哥,我知道我错哪了,就把 else 0 改位else null就ok了
dajian2000 2003-10-15
  • 打赏
  • 举报
回复
为什么要把userindex写进去?想靠它提高检索速度吗?
用楼上的方法就好了,它同样利用了索引userindex 。
pengdali 2003-10-15
  • 打赏
  • 举报
回复
你这样写不行吗?

select userindex 用户编号,
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 ;
pengdali 2003-10-15
  • 打赏
  • 举报
回复
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 ;
什么是数据仓库呢?数据仓库是一个为数据分析而设计的企业级数据管理系统。数据仓库可集中、整合多个信息源的大量数据,借助数据仓库的分析能力,企业可从数据中获得宝贵的信息进而改进决策。同时,随着时间的推移,数据仓库中积累的大量历史数据对于数据科学家和业务分析师也是十分宝贵的。 数据仓库建模的意义是什么呢?如果把数据看作图书馆里的书,我们希望看到它们在书架上分门别类地放置;如果把数据看作城市的建筑,我们希望城市规划布局合理;如果把数据看作电脑文件和文件夹,我们希望按照自己的习惯有很好的文件夹组织方式,而不是糟糕混乱的桌面,经常为找一个文件而不知所措。数据模型就是数据组织和存储方法,它强调从业务、数据存取和使用角度合理存储数据。只有将数据有序的组织和存储起来之后,数据才能得到高性能、低成本、高效率、高质量的使用。 数据仓库建模的最终目的是什么呢?高性能:良好的数据模型能够帮助我们快速查询所需要的数据。低成本:良好的数据模型能减少重复计算,实现计算结果的复用,降低计算成本。高效率:良好的数据模型能极大的改善用户使用数据的体验,提高使用数据的效率。高质量:良好的数据模型能改善数据统计口径的混乱,减少计算错误的可能性。 本课程将基于理论和实践讲解数据仓库,包含基础知识:数据仓库建模方法论、数据仓库分层模型、数据仓库构建流程、事实表、维度表、指标体系、拉链表、维度模型等 ,基于真实电商业务作为实战,讲解电商数仓的整个构建过程,让大家在实战中理解和掌握数仓的理论知识。

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧