我正在使用以下 SQL 查询来比较两个 Excel 工作表(两者的设置差异)
strSql = "SELECT [CD_CLIENTE], [NM_CLIENTE], [CPF/CNPJ], [DS_DOCUMENTO], [DTVALIDADE] FROM [BaseAnterior$] " & _
"WHERE NOT EXISTS ( " & _
"SELECT * FROM [BaseAtual$] WHERE" & _
"[BaseAtual$].[CD_CLIENTE] = [BaseAnterior$].[CD_CLIENTE] AND " & _
"[BaseAtual$].[NM_CLIENTE] = [BaseAnterior$].[NM_CLIENTE] AND " & _
"[BaseAtual$].[DS_DOCUMENTO] = [BaseAnterior$].[DS_DOCUMENTO] AND " & _
"[BaseAtual$].[CPF/CNPJ] = [BaseAnterior$].[CPF/CNPJ] AND " & _
"[BaseAtual$].[DTVALIDADE] = [BaseAnterior$].[DTVALIDADE]" & _
")"
该语句工作正常,问题是它非常缓慢。工作表有 aprox。100k 条记录(不要问我为什么它们不在一个严肃的数据库中)并且执行可能需要几分钟。我知道问题出在我的 SQL 语句上,所以我的问题是:有没有更快的方法来选择 SQL 中的集合差异?