ITPub博客

首页 > > > 执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高

执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高

作者:amadan 时间:2019-11-05 11:59:57 0 删除 编辑

我要统计数据库表15张表的条数,以下两种方案哪个执行的快一些:

方案一:

执行15次统计SQL:

select count(1) from 表1 where条件

select count(1) from 表2 where条件

.........

select count(1) from 表15 where条件

方案二:

使用一条SQL一下子统计出15张表的条数:

select

(select count(1) from 表1 where条件) t1_count,

(select count(1) from 表2 where条件) t2_count,

........

(select count(1) from 表15 where条件) t15_count,

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2310/viewspace-3139078/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-06

  • 博文量
    200
  • 访问量
    14412