Can anyone show me an example of how to get the statistical mode (most frequent value) from an SQL database column?
For example, let Sample be a column of sample values in Table, something like:
2,5,6,2,3,5,3,2,6,1
then the mode would be 2.
I found this example on the web which I tried to apply to my own code, but doing the query returns an error in the "Sample LIMIT 1" part
With trial and error I found that
doesn't cause an error, but it returns the least frequent value (1), not the mode frequent (2), from the column?
I'll be the first to admit I'm clueless here. But in compensation I often DONATE to the one with the most helpful solution to my questions - without insulting or criticizing me for not being smart enough to write my own code
For example, let Sample be a column of sample values in Table, something like:
2,5,6,2,3,5,3,2,6,1
then the mode would be 2.
I found this example on the web which I tried to apply to my own code, but doing the query returns an error in the "Sample LIMIT 1" part
B4X:
Dim query As String
Dim result As Int
query = "SELECT Sample AS Mode FROM Table GROUP BY 1 ORDER BY COUNT(1) Sample LIMIT 1"
result = SQL1.ExecQuerysingleresult(query)
Log("Mode (Sample) = " & result)
B4X:
query = "SELECT Sample as Mode FROM Table GROUP BY 1 ORDER BY COUNT(1) LIMIT 1"
I'll be the first to admit I'm clueless here. But in compensation I often DONATE to the one with the most helpful solution to my questions - without insulting or criticizing me for not being smart enough to write my own code