一、需求场景:
通过查询出两个数据集后再根据条件合并
select M1.*,M2.* from M1 left join M2 ON M2.TA001 = M1.TA001 AND M2.TA002=M1.TA002
二、通过FireDac 强大的TFDLocalSQL控件
try with dmMain do begin FDQueryD.Close; FDQueryD.open; FDMemTableD.Data := FDQueryD.Data; FDQueryD.Close; // FDQueryD.Active := False; FDQueryM.Close; FDQueryM.open; FDMemTableM.Data := FDQueryM.Data; FDQueryM.Close; try LocalSQL.DataSets.Add(FDMemTableM, ‘‘, ‘M1‘); LocalSQL.DataSets.Add(FDMemTableD, ‘‘, ‘M2‘); LocalSQL.Active := True; // 需激活 LocalQuery.Close; LocalQuery.open (‘select M1.*,M2.* from M1 left join M2 ON M2.TA001 = M1.TA001 AND M2.TA002=M1.TA002 ‘); FDMemTableQuery.Close; FDMemTableQuery.Data := LocalQuery.Data; FDMemTableQuery.Active; finally LocalSQL.DataSets.Clear; end; end; except on E: Exception do ShowMessage(E.Message); end;