首页 新闻 会员 周边

复杂的SQL语句是改为执行多条效率快,还是执行一条效率快

-2
解决于 2019-10-30 21:30

我要统计数据库表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,

泱泱的主页 泱泱 | 初学一级 | 园豆:2
提问于:2018-04-26 10:27
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册