在一个语句中合并两个SQL查询 [英] Combine Two SQL queries in one statement

查看:154
本文介绍了在一个语句中合并两个SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将两个SQl查询合并成一个

How to combine the two SQl Queries into one

在我的案例3表名称

 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服务器可以使用EXCEPT

If you're using SQL server you can use the EXCEPT

Select Sum() From Table 1 Where Table=....** 
EXCEPT
Select Sum() From Table 2 Where Table 2=........**  

这篇关于在一个语句中合并两个SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆