简体   繁体   English

强大的查询功能可基于Excel列列表过滤SQL视图

[英]Power Query to Filter a SQL view based on an Excel column list

Is there a way to filter a SQL view based on a list of values in an excel table column using Power Query? 有没有一种方法可以使用Power Query根据excel表列中的值列表过滤SQL视图?

I have a SQL view that returns a large set of data (millions of records or properties). 我有一个SQL视图,该视图返回大量数据(数百万条记录或属性)。 Users want to filter that based on an excel table column of property IDs. 用户希望基于属性ID的excel表列进行过滤。 I know I can just do a merge join based on the property ID between the view and the excel column in power query. 我知道我可以基于视图和Power查询中的excel列之间的属性ID进行合并联接。 But it looks like the merge brings in the millions of records first then filtered it in the join. 但是合并似乎首先带来了数百万条记录,然后在联接中对其进行了过滤。 Which takes a long time. 这需要很长时间。 Users want to change the list of propertyIDs on the fly on a daily basis and run the query. 用户希望每天动态更改propertyID列表并运行查询。

Essentially, I wanted to create in Excel power query what is in SQL 本质上,我想在Excel Power查询中创建SQL中的内容

SELECT * FROM SQLViewName 
WHERE PropertyID IN (Select Column from ExcelTable) 

You should be able to do this with a List.Contains function. 您应该能够使用List.Contains函数执行此操作。

If my ExcelTable is 如果我的ExcelTable

ID
---
436
437
438
439

then adding a filter like this should do the trick: 然后添加这样的过滤器就可以解决问题:

Table.SelectRows(SQLViewName, each List.Contains(ExcelTable[ID], [PropertyID]))

When I tried this and did View Native Query on the last applied step, it folded the Excel table into a WHERE clause with the ExcelTable values as literals like this: 当我尝试此操作并在最后应用的步骤中执行“查看本机查询”时,它会将Excel表折叠为WHERE子句,其中ExcelTable值作为文字,如下所示:

select [_].[PropertyID],
    [_].[OtherColumns]
from [dbo].[SQLViewName] as [_]
where [_].[PropertyID] in (436, 437, 438, 439)

This allowed me to load a multi-million-row table in just a couple seconds. 这使我可以在短短几秒钟内加载数百万行的表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM