当前位置: 代码迷 >> Oracle开发 >> 帮忙看看这个SQL如何优化一下?多谢了
  详细解决方案

帮忙看看这个SQL如何优化一下?多谢了

热度:84   发布时间:2016-04-24 06:48:40.0
帮忙看看这个SQL怎么优化一下?谢谢了
  select A =
         (select COUNT(*)from Activity where CrtUserID = 178864 and State = 0) *
         (select CKey1 from Category where CategoryID = 1004) +
         ((select COUNT(*) from ActivityCmt where CrtUserID = 178864 and State = 0) +  (select COUNT(*) from TopicCmt where CrtUserID = 178864 and State = 0) +(select COUNT(*) from PhotoCmt where CrtUserID = 178864 and State = 0)) *
         (select CKey1 from Category where CategoryID = 1006) +
         ((select COUNT(*) from ActivityPhotos where CrtUserID = 178864 and State = 0) + (select COUNT(*) from Photos where CrtUserID = 178864 and State = 0)) *
         (select CKey1 from Category where CategoryID = 1015) +
         (select COUNT(*) from Topic where CrtUserID = 178864 and State = 0) *
         (select CKey1 from Category where CategoryID = 1001) +
         (select COUNT(*)from Tweet  where CrtUserID = 178864 and State = 0) *
         (select CKey1 from Category where CategoryID = 1002)


谢谢各位搭救了~~
------解决方案--------------------
一堆没任何联系的表 怎么优化?

sql是不能下手 只能从其他方面考虑了...
------解决方案--------------------
引用:
Quote: 引用:

离开了表结构,索引字段,数据分布和业务要求的优化,都是耍流氓

这~~什么意思?不懂~~


sql优化说白了是算法针对当前业务逻辑和数据分布的一种固化算法
离开了这些,剩下能做的就不多了,无非就是建建索引,建建分区表什么的
------解决方案--------------------
这种计算类的语句不可能优化。
楼主应该也是编程的,可以像程序一样写成函数。
------解决方案--------------------
这个对where后面的字段做好索引就是优化
  相关解决方案