SELECT TOP 1 num, COUNT(num) AS times FROM Score GROUP BY num ORDER BY times DESC写错了,纠正~~是从Score表里面,选出出现最多的num列的数值,及次数
select top 1 count(id) as fid,id from acct_class group by id order by fid desc
还不够详细啊,我晕~~~~ 已经是SQL语句了 你只要把num换成你的自段名就可了 Score:换成你的表名SELECT TOP 1 num, COUNT(num) AS times FROM Score GROUP BY num ORDER BY times DESC
试试: SELECT id, max(COUNT(id)) AS maxnum FROM Score GROUP BY id
用OpenRecordset语句将上述SQL打开。
Sub ReadIt() Dim sSQL As String Dim oRS As ADODB.Recordset Dim sName As String Dim nIndex As Integer Dim lTimes as Long sSQL = "SSELECT TOP 1 num, COUNT(num) AS times FROM Score GROUP BY num ORDER BY times DESC" Set oRS = GetRecordset(sSQL) If oRS Is Nothing Then Alert "Common Database Error" Else With oRS If .EOF = True And .BOF = True Then 'Alert "No Kind FOUND!Please Insert Kind First" Else .MoveFirst sName = .Fields(0).Value lTimes = .Fields(1).Value End If End With End If txtNum.Text=sName txtTimes.text=lTimes End SubPublic Function GetRecordset(ByVal sSQL As String) As ADODB.Recordset On Error Resume Next With goCon .CommandTimeout = 30 .CursorLocation = adUseClient Set GetRecordset = .Execute(sSQL) End With 'If Err.Number <> 0 Then PutToLog Err.Description, , sSQL End FunctionPublic Function InitDB(ByVal sServerName As String) As Boolean On Error Resume Next
FROM Score
GROUP BY num
ORDER BY times DESC写错了,纠正~~是从Score表里面,选出出现最多的num列的数值,及次数
group by id
order by fid desc
已经是SQL语句了
你只要把num换成你的自段名就可了
Score:换成你的表名SELECT TOP 1 num, COUNT(num) AS times
FROM Score
GROUP BY num
ORDER BY times DESC
SELECT id, max(COUNT(id)) AS maxnum
FROM Score
GROUP BY id
Dim sSQL As String
Dim oRS As ADODB.Recordset
Dim sName As String
Dim nIndex As Integer
Dim lTimes as Long
sSQL = "SSELECT TOP 1 num, COUNT(num) AS times FROM Score GROUP BY num ORDER BY times DESC" Set oRS = GetRecordset(sSQL)
If oRS Is Nothing Then
Alert "Common Database Error"
Else
With oRS
If .EOF = True And .BOF = True Then
'Alert "No Kind FOUND!Please Insert Kind First"
Else
.MoveFirst
sName = .Fields(0).Value
lTimes = .Fields(1).Value
End If
End With
End If
txtNum.Text=sName
txtTimes.text=lTimes
End SubPublic Function GetRecordset(ByVal sSQL As String) As ADODB.Recordset
On Error Resume Next
With goCon
.CommandTimeout = 30
.CursorLocation = adUseClient
Set GetRecordset = .Execute(sSQL)
End With
'If Err.Number <> 0 Then PutToLog Err.Description, , sSQL
End FunctionPublic Function InitDB(ByVal sServerName As String) As Boolean
On Error Resume Next
gsCon = "DSN=你的DSN;" & _
"SERVER=" & sServerName & ";""
With goCon
.Open gsCon
.CommandTimeout = 30
.CursorLocation = adUseClient
End With
InitDB = (Err.Number = 0)
End Function够详细了吧?呵呵