I do not think you can get a single value using an aggregate query where you are grouping by two columns. I think the query returns a cursor like this, although I stand corrected:
B4X:
Dim MyQuery As String = "Select ifnull(COUNT(*),'0') AS MyCount FROM GamePlay GROUP BY teamscore, teamround HAVING COUNT(*) > 1"
curs=SQL1.ExecQuery(MyQuery)
For i=0 To curs.RowCount-1
curs.Position=i
Log($"my count is: ${curs.Getint("MyCount")}"$ )
Next
curs.Close
I tested the concept on one of my databases, with different columns of course and I was able to view results in the cursor.
Yes it does if there are duplicates. But it doesn't if there aren't any duplicates and I need it to if it doesn't have duplicates. Or should I say it shouldn't error out if there aren't any duplicates.
Yes it does if there are duplicates. But it doesn't if there aren't any duplicates and I need it to if it doesn't have duplicates. Or should I say it shouldn't error out if there aren't any duplicates.
Dim ThereAreDuplicates As Boolean
Dim MyQuery AsString = "Select COUNT(*) AS MyCount FROM GamePlay GROUP BY teamscore, teamround HAVING MyCount > 1"
curs = SQL1.ExecQuery(MyQuery)
ThereAreDuplicates = (curs.RowCount > 0)
curs.Close
IfNull seems not working when you use Count (it works well using Sum, for example )
Sub CountDuplicate() As Int
Dim qry As String
Dim cur As Cursor
Try
qry = "SELECT COUNT(*) AS duplicate_count FROM GamePlay GROUP BY teamscore, teamround HAVING duplicate_count > 1"
cur = SQL.ExecQuery(qry)
Return cur.RowCount
Catch
Log("Error: " & LastException.Message)
Return 0
End Try
End Sub
I do not think you need the catch block because there is no error when the count is 0. The code can be simply as follows:
B4X:
Sub CountDuplicate() As Int
Dim qry As String
Dim cur As Cursor
qry = "SELECT COUNT(*) AS duplicate_count FROM GamePlay GROUP BY teamscore, teamround HAVING duplicate_count > 1"
cur = SQL.ExecQuery(qry)
Return cur.RowCount
End Sub
I do not think you need the catch block because there is no error when the count is 0. The code can be simply as follows:
B4X:
Sub CountDuplicate() As Int
Dim qry As String
Dim cur As Cursor
qry = "SELECT COUNT(*) AS duplicate_count FROM GamePlay GROUP BY teamscore, teamround HAVING duplicate_count > 1"
cur = SQL.ExecQuery(qry)
Return cur.RowCount
End Sub