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

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

发布时间:2020-12-12 16:09:41 所属栏目:MsSql教程 来源:网络整理
导读:我有两个查询: 查询简化,不包括连接 Query 1 : select ProductName,NumberofProducts (in inventory) from Table1.....;Query 2 : select ProductName,NumberofProductssold from Table2......; 我想知道如何得到一个输出: ProductName NumberofProducts(in
我有两个查询:
查询简化,不包括连接
Query 1 : select ProductName,NumberofProducts (in inventory) from Table1.....;
Query 2 : select ProductName,NumberofProductssold from Table2......;

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

ProductName NumberofProducts(in inventory)  ProductName NumberofProductsSold

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

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

解决方法

这是一个在两个完全不相关的表之间进行联合的示例:“学生”和“产品”表.它生成一个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

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

(编辑:李大同)

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

    推荐文章
      热点阅读