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:
随机推荐
- espcms内容页上下篇按后台手动排序号
模板文件: {%get name=plist class="did":$read.did,pid:$read.pid%} <li class="fl"&g ...
- HDU 4113 Construct the Great Wall(插头dp)
好久没做插头dp的样子,一开始以为这题是插头,状压,插头,状压,插头,状压,插头,状压,无限对又错. 昨天看到的这题. 百度之后发现没有人发题解,hust也没,hdu也没discuss...在acm- ...
- 让EF飞一会儿:如何用Entity Framework 6 连接Sqlite数据库
获取Sqlite 1.可以用NuGet程序包来获取,它也会自动下载EF6 2.在Sqlite官网上下载对应的版本:http://system.data.sqlite.org/index.html/do ...
- Android笔记:android的适配
public int Dp2Px(Context context, float dp) { final float scale = context.getResources().getDisplayM ...
- NYOJ题目27水池数目
--------------------------------------------- 这道题有点坑,也怪我总是有点马虎,按照正常人的思维0是表示有水池啊竟然是1表示有水池,最坑的是写反了竟然还能 ...
- LeetCode之283. Move Zeroes
---------------------------------------------------------------------- 解法一:空间换时间 我使用的办法也是类似于"扫描 ...
- c#关于类的继承
public class D { public virtual void Run(string name) { Console.WriteLine(name + ",good"); ...
- 全站 HTTPS 来了
!版权声明:本文为腾讯Bugly原创文章,转载请注明出处腾讯Bugly特约作者:刘强 最近大家在使用百度.谷歌或淘宝的时候,是不是注意浏览器左上角已经全部出现了一把绿色锁,这把锁表明该网站已经使用了 ...
- haohantech浩瀚盘点机“PDA无线订货开单”终端 移动现场下单APP(打印扫描一体)
手持PDA盘点机,订货的时候,用PDA上自带的激光扫描头扫描(或手输)样品的条码,然后,只需输入该款产品不同尺码的数量即可自动(或手动)发送订货数据到总部服务器.盘点机“PDA无线订货”终端功能: 1 ...
- 转载:持续集成之解决jenkins内存溢出问题
在jenkins master-slave配置中,总是出现内存溢出问题,更换了机器设备仍然跑不起来: 问题如下: Status Code: 500 Exception: org.apache.c ...