sql – 如何将两个查询的结果合并到单个数据集中

前端之家收集整理的这篇文章主要介绍了sql – 如何将两个查询的结果合并到单个数据集中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个查询
查询简化,不包括连接
Query 1 : select ProductName,NumberofProducts (in inventory) from Table1.....;
Query 2 : select ProductName,NumberofProductssold from Table2......;

我想知道如何得到一个输出

ProductName NumberofProducts(in inventory)  ProductName NumberofProductsSold

用于获取每个查询输出的关系是不同的.
我需要输出这种方式为我的SSRS报告.

(我尝试了工会声明,但它不适用于我想看到的输出.)

@R_301_323@

这是一个在两个完全不相关的表之间进行联合的示例:“学生”和“产品”表.它生成一个4列的输出
select FirstName as Column1,LastName as Column2,email as Column3,null as Column4 from Student
union
select ProductName as Column1,QuantityPerUnit as Column2,null as Column3,UnitsInStock as Column4 from Products

显然你会调整自己的环境…

原文链接:https://www.f2er.com/mssql/82501.html

猜你在找的MsSQL相关文章