Cross join in excel --- Copy from Internet
Set up the Workbook
In this example, there are two tables -- Raw Materials and Packaging -- and each table is on a separate worksheet.
The Raw Materials table is on the sheet named Materials, and the Packaging table is on the sheet named Packaging.
The third sheet in the workbook is named Combined, and this is where the query results will be stored.

With Microsoft Query, you can create a list that combines each item in one table, with all the items in the other table -- a Cartesian join, also called a cross join. You can read more about the different join types on the Microsoft website: Description of the usage of joins in Microsoft Query
Open MS Query
To create the Cartesian (cross) join, you'll use MS Query.
- On the Excel Ribbon, click the Data tab
- In the Get External Data group, click From Other Sources, then click From Microsoft Query

- In the Choose Data Source window, click on Excel Files*, and click OK

- In the Select Workbook window, locate and select the current workbook, and click OK.

- In the Query Wizard, if you don't see the sheet names listed, click Options, and add a check mark to System Tables

- Click Materials$, and click the arrow to put the Raw Materials column in the query.
- Click Packaging$, and click the arrow to put the Packaging column in the query

- Click Cancel, to close the Query Wizard, and click Yes when prompted.

- In Microsoft Query, double-click on Raw Materials in the Materials$ table, to add it to the query grid.
- Then, double-click on Packaging, to add it to the query grid.

- Click the Return Data button, to send the data to Excel.

Create a Worksheet Table
It might take a few seconds, but then the Import Data window will open.
- In the Import Data window, select Table
- Select the cell on the worksheet where you want to place the query results, and click OK.

- A table is created, and shows all the items from each table, in all possible combinations.

Add Formulas to the Table
You can add formulas to the table, in a new column. The formulas will automatically adjust if the source tables are changed.
- Type a new heading in cell C1 -- MatPack -- and press Enter
- A new column is automatically included in the table.
- In cell C2, type a formula to combine the text in columns A and B, with a space character between them:
=[@[Raw Materials]] & " " & [@Packaging]
- Then, copy the formula down to the last row of data in the table.

Update the Table
You can update the source tables, and then update the query results table, to show the revised data.
- Add a new item to each of the source tables. In this example, Boxes was added to the Packaging list, and Cream was added to the Raw Materials list.

- On the Excel Ribbon, click the Data tab, and click Refresh All.

- The new items are shown in the updated query results table.

Manually Update the Workbook Name
If you change the workbook name, the query will need to be updated, before it will run. To manually update the query:
- Right-click a cell in the results table, and click Refresh
- When the Login Failed message appears, click OK

- In the Select Workbook window, locate and select the new workbook, and click OK.

Update the Query Connection with VBA
If the file name or location will change frequently, you can use programming to automatically change the file location in the connection.
Paste the following code -- FixQueryConnection -- into a regular module in the workbook, and then run the code when the workbook opens, by adding a Workbook_Open event.
This code was tested in Excel 2010 (32-bit), and might need to be adjusted for other versions of Excel.
Sub FixQueryConnection()
'
Dim strFile As String
Dim strPath As String
Dim strQry As String
Dim strCmd As String
Dim strConn As String strPath = ActiveWorkbook.Path & "\"
strFile = ActiveWorkbook.Name
strQry = "Query from Excel Files"
strCmd = "SELECT `Materials$`.`Raw Materials`, `Packaging$`.Packaging "
strCmd = strCmd & "FROM `Materials$` `Materials$`, `Packaging$` `Packaging$`"
strConn = "ODBC;DSN=Excel Files;DBQ=" & strPath & strFile
strConn = strConn & ";DefaultDir=" & strPath
strConn = strConn & ";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'
With ActiveWorkbook.Connections(strQry).ODBCConnection
.BackgroundQuery = True
.CommandText = strCmd
.CommandType = xlCmdSql
.Connection = strConn
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections(strQry)
.Name = strQry
.Description = ""
End With
ActiveWorkbook.Connections(strQry).Refresh ActiveWorkbook.RefreshAll
End Sub
'====================================
Put this code into the ThisWorkbook module:
Private Sub Workbook_Open()
FixQueryConnection
End Sub
'====================================

Get Excel News





Copyright © Contextures Inc. 2016
Cross join in excel --- Copy from Internet的更多相关文章
- SQL中inner join、outer join和cross join的区别
对于SQL中inner join.outer join和cross join的区别简介:现有两张表,Table A 是左边的表.Table B 是右边的表.其各有四条记录,其中有两条记录name是相同 ...
- CROSS JOIN连接用于生成两张表的笛卡尔集
将两张表的情况全部列举出来 结果表: 列= 原表列数相加 行= 原表行数相乘 CROSS JOIN连接用于生成两张表的笛卡尔集. 在sql中cross join的使用: 1.返回的记录数为两个 ...
- left join ,right join ,inner join ,cross join 区别
left join ,right join ,inner join ,cross join 区别(参考:http://zhidao.baidu.com/link?url=gpOl9HXZR0OrQuy ...
- MySQL的几种连接 join/inner join/cross join/逗号/left join/right join/natural join
转载请注明出处!! 之前数据表连接操作多使用逗号或者join,对几种连接的概念一直浑浑噩噩,最近研究了一波,把这些连接的区别搞明白了. 连接:A xjoin B(主表 操作 关联表) selec ...
- 用实例展示left Join,right join,inner join,join,cross join,union 的区别
1.向TI,T2插入数据: T1 7条 ID Field2 Field3 Field41 1 3 542 1 3 543 1 3 544 2 3 545 3 3 546 4 3 547 5 3 54 ...
- Linq表连接大全(INNER JOIN、LEFT OUTER JOIN、RIGHT OUTER JOIN、FULL OUTER JOIN、CROSS JOIN)
我们知道在SQL中一共有五种JOIN操作:INNER JOIN.LEFT OUTER JOIN.RIGHT OUTER JOIN.FULL OUTER JOIN.CROSS JOIN 1>先创建 ...
- FULL JOIN 与 CROSS JOIN
FULL JOIN 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行.(返回JOIN 两端表的所有数据,无论其与另一张表有没有匹配.显示左连接.右连接和内连接的并集) FULL JOIN ...
- SQL表连接查询(inner join(join)、full join、left join、right join、cross join)
下面列出了您可以使用的 JOIN 类型,以及它们之间的差异. JOIN: 如果表中有至少一个匹配,则返回行(join=inner join) LEFT JOIN: 即使右表中没有匹配,也从左表返回所有 ...
- CROSS JOIN,NATURAL JOIN
CROSS JOIN:笛卡尔积 NATURAL JOIN:
随机推荐
- c#.net 生成清晰缩略图
1 public void imgsize() 2 { 3 //本例中假定了两个变量: 4 5 String src = "c:/myImages/a.jpg"; //源图像文件的 ...
- React-native 学习记录
在此记录下学习中的小知识 今天在componentWillUpdate调用this.setState方法,想达到一个效果:就像viewWillAppear时,系统从网络请求新的数据,并刷新界面, 但是 ...
- [Linux]系统调用理解(3)
本文介绍了Linux下的进程的一些概念,并着重讲解了与Linux进程管理相关的重要系统调用wait,waitpid和exec函数族,辅助一些例程说明了它们的特点和使用方法. 1.7 背景 在前面的文章 ...
- Scrapy003-项目流程
Scrapy003-项目流程 @(Spider)[POSTS] 前两篇文章我们了解到Scrapy的原理和安装的相关知识,这节就需要知道创建项目流程的小知识. 根据官方文档:http://scrapy- ...
- VC++ 应用程序无法正常启动0xc0150002
使用VC++开发软件,编译后的程序打不开,弹出错误框: 使用Dpends Walker查看依赖项,没有什么异常. 然后,右键"计算机",选择"管理",打开计 ...
- git mac客户端使用提交与同步
点击file -> add local repository 将本地已经存在的git库添加到客户端中 当项目有改变时,点击正上方居中的Uncommitted Change按钮查看改变的内容 在 ...
- .NET LINQ基本查询操作
获取数据源 在 LINQ 查询中,第一步是指定数据源.像在大多数编程语言中一样,在 C# 中,必须先声明变量,才能使用它.在 LINQ 查询中,最先使用 from 子句的目的是引入数据源 ( ...
- 开发微信App支付
1.首先到官方下载Demo,地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1 下载后的目录结构如下:
- ASP.NET知识总结(5.文件上传 文件下载)
5.文件上传 ->说明:使用http协议只适合传输小文件,如果想传递大文件,则需要使用插件或者客户 端程序(使用ftp协议) ->客户端操作 <1>为表单添加属性:encty ...
- .NET中RabbitMQ的使用
概述 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public ...