微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

参见英文答案 > 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=........**

原文地址:https://www.jb51.cc/mssql/83791.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐