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:
随机推荐
- from collections import OrderedDict
在python中,dict这个数据结构由于hash的特性,是无序的,这在有时候会给我们带来一些麻烦,幸运的是, collections模块为我们提供了OrderdDict,当你要获取一个有序的字典对象 ...
- php命名空间
命名空间概述 (PHP 5 >= 5.3.0, PHP 7) 什么是命名空间?从广义上来说,命名空间是一种封装事物的方法.在很多地方都可以见到这种抽象概念.例如,在操作系统中目录用来将相关文件分 ...
- Spring MVC+FreeMarker简介
最近做项目,刚接触到SpringMVC与FreeMarker框架,就简单介绍一下自己的理解,不正确的地方请大家指教!! 1.Spring MVC工作原理: 用户发送请求--->前端服务器去找相对 ...
- C#导出涉及行列合并的复杂的Excel数据
一.导出数据格式 二.实现代码 /// <summary> /// 导出经费统计excel表格 /// </summary> /// <param name=" ...
- go:系统参数or函数--未完
系统参数: os.Args 存放命令参数的字符串数组,其中os.Arg[0]为命令本身的路径,其余项存放输入的参数 例:$ go run myapp.exe -d /home os.Args[0]: ...
- 【目录】python
python 入门学习(一) 入门学习(二) 入门学习(三) 入门学习(四) 入门学习(五) 入门学习(六) 入门学习(七) 入门学习(八) 入门学习(九) 入门学习(十) Head First Py ...
- 自定义RatingBar,不同分辨率屏幕下图片拉伸或者显示不完整问题解决
1.需要两张评分图片ic_rating_highlight.png ic_rating_normal_white.png(宽高都是52px,且有内边距) 将这两张图片添加到各分辨率文件夹下 开发过 ...
- tp框架之查询
//数据访问 //造模型对象 $nation = D("Nation"); //查询 //$a = $nat ...
- 工欲善其事-Eclipse设置
1.注释设置 [重要可以保存使用] 在菜单栏Window--->Preferences--->Java--->Code Style--->Code Templates然后展示C ...
- 【MyEcplise】build workspace卡死
1.window-Perferences-MyEclipse-Validation 将Manual全部勾掉,Build只留Classpath DependencyValidator,其它全部勾掉. 2 ...