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

mssql sqlserver两条求和sql脚本相加的方法分享

发布时间:2020-12-12 14:22:33 所属栏目:MsSql教程 来源:网络整理
导读:转自:http://www.maomao365.com/?p=7205 摘要: 下文分享两条sql求和脚本,再次求和的方法分享 / * 例: 下文已知两条sql求和脚本,现需对两张不同表的求和记录再次求和 */ -- -对两条求和sql脚本求和的方法 select sum (q) from ( select sum (qty) as q fro

转自:http://www.maomao365.com/?p=7205

摘要:
下文分享两条sql求和脚本,再次求和的方法分享

*
     例:
       下文已知两条sql求和脚本,现需对两张不同表的求和记录再次求和   
     */  
     ---对两条求和sql脚本求和的方法
      select sum(q) from 
      (
       select sum(qty)  as q from tableNameA where ...
       union all 
        select sum(qty)  as q from tableNameB where ...
       ) as table
     
     ---对多条求和sql脚本,再次求和的方法分享
     select sum(q) from 
      (
       select sum(qty)  as q from tableNameA where ...
       union all 
        select sum(qty)  as q from tableNameB where ...
         union all 
        select sum(qty)  as q from tableNameC where ...
        union all 
        select sum(qty)  as q from tableNameD where ...
       ...  
    ) as table

(编辑:李大同)

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

    推荐文章
      热点阅读