sql语句查询excel 2003表,求一sql语句
一个excel表格,4列,6万行左右。
例表:
A B C D
0 1 1 5
1 2 3 2
0 7 1 6
3 2 2 2
0 6 3 7
3 1 1 7
要查询A列和C列同时重复的记录,比如上面的第一、第三行……
Dim lsSql As String
Dim lrRec As ADODB.Recordset
Dim ldbConn As New ADODB.Connection
ldbConn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Extended Properties=DSN=Excel Files;DBQ=" & "c:\1.xls; DefaultDir=c:\ ;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
ldbConn.Open
lsSql = "SELECT * "
lsSql = lsSql & "......."
Set lrRec = New ADODB.Recordset
lrRec.CursorLocation = adUseClient
lrRec.Open lsSql, ldbConn, adOpenForwardOnly, adLockReadOnly
[解决办法]
Excel 可以当作 Jet Enine 的外部数据库来查询。
不过 SQL 语句无法直接支持重复判断的查询。需要多条语句或嵌套语句来实现。例如:
Select * From yourtable Where A*10+C IN (Select x From (Select A*10+C As x, Count(*) As m Group by A*10+C) Where m > 1)