在一个语句中组合两个SQL查询[重复]

时间:2021-01-15 01:12:11

This question already has an answer here:

这个问题在这里已有答案:

How to combine the two SQl Queries into one

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

In My case 3 Tables Name

在我的情况下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'"

what I want

我想要的是

     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'"

I ask similar question Before but its time it is a SQL statement so Please Don't connect it with the previous one

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

1 个解决方案

#1


1  

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

如果您使用的是SQL Server,则可以使用EXCEPT

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

#1


1  

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

如果您使用的是SQL Server,则可以使用EXCEPT

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