加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – sql计数总和

发布时间:2020-12-12 08:41:29 所属栏目:MsSql教程 来源:网络整理
导读:我有两个表,并且想要每个表中的总行数.实际的查询更复杂,因为每个计数都会存在…子句 如何在t-sql中执行以下操作? select count(*) from table1 + count(*) from table2 要么 select sum(count(*) from table1,count(*) from table2) 解决方法 select (selec
我有两个表,并且想要每个表中的总行数.实际的查询更复杂,因为每个计数都会存在…子句

如何在t-sql中执行以下操作?

select count(*) from table1 + count(*) from table2

要么

select sum(count(*) from table1,count(*) from table2)

解决方法

select  (select count(PrimaryKeyID) from  FirstTable) 
      + (select COUNT(PrimaryKeyID) from TableSecond)

所以我认为我们应该避免在下面的查询中使用星号.因为它可能会导致查询中的性能下降

select  (select count(*) from  FirstTable) 
      + (select COUNT(*) from TableSecond)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读