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

在一个语句中组合两个SQL查询

发布时间:2021-02-06 19:30:41 所属栏目:MsSql教程 来源:网络整理
导读:参见英文答案 Store two Queries result in third variable3个 如何将两个SQl查询合并为一个 在我的情况下3表名称 Remain_cotton,add_cotton,Sell_Table conn.Execute _ "INSERT INTO Remain_Cotton(No_Of_Bottle) " _ "SELECT sum(No_Of_Bottle)" _ "FROM

参见英文答案 > Store two Queries result in third variable3个
如何将两个SQl查询合并为一个

在我的情况下3表名称

Remain_cotton,add_cotton,Sell_Table

conn.Execute _
    "INSERT INTO Remain_Cotton(No_Of_Bottle) " & _
    "SELECT sum(No_Of_Bottle)" & _
    "FROM add_cotton Where Cateogry='Large'"

   conn.Execute _
    "INSERT INTO Remain_Cotton(Quantity) " & _
    "SELECT sum(Quantity)" & _
    "FROM Sell_Detail Where Cateogry='Large'"

我想要的是

conn.Execute _
    "INSERT INTO Remain_Cotton(No_Of_Bottle)(Quantity) " & _
    "SELECT sum(No_OF_Bottle),sum(Quantity)" & _
    "FROM add_cotton,Sell_Detail Where Cateogry='Large'"

我问类似的问题之前但它的时间是一个SQL语句所以请不要将它与前一个连接

解决方法

如果您使用的是SQL Server,则可以使用EXCEPT
Select Sum() From Table 1 Where Table=....** 
EXCEPT
Select Sum() From Table 2 Where Table 2=........**

(编辑:武汉站长网)

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

    热点阅读