差不多2个月没用数据库了,手生的很。 重新学习,并简化了fig的代码 Sub ldy简化() With Worksheets("连续3天失败标记") Set CNN = CreateObject("adodb.connection") CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=yes;';Data Source=" & ThisWorkbook.FullName .Range("f2:i1000").ClearContents Sql = "(select * FROM [连续3天失败标记$a1:d888] a, [连续3天失败标记$a1:d888] b, [连续3天失败标记$a1:d888] c where a.num=b.num and b.num=c.num and a.operation=b.operation and b.operation=c.operation and day(b.dt)-day(a.dt)=1 and day(c.dt)-day(b.dt)=1)" Sql = "select a.num,a.operation,a.dt,a.errtype from " & Sql & " union select b.num,b.operation,b.dt,b.errtype from" & Sql & " union select c.num,c.operation,c.dt,c.errtype from " & Sql Sql = "select aa.num,aa.operation,aa.dt,aa.errtype from [连续3天失败标记$a1:d888] aa, (" & Sql & ") bb where aa.num & aa.operation & aa.dt & aa.errtype = bb.num & bb.operation & bb.dt & bb.errtype" .Range("f2").CopyFromRecordset CNN.Execute(Sql) End With End Sub |