Android Question B4x table Create data view with max and min value in

GJREDITOR

Member
I need to show the maximum and minimum marks in b4xtable. I get the data from Google sheet and I am displaying it in b4xtable. I tried using the below code to get maximum and minimum data . Obviously the code is wrong as I get the error : "java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such column: MAXc3)". Could someone guide me as to how to get maximum and minimum value and either highlight it or create a dataview?
Get maximum in 'NEET Mark Column':
'NumberColumn = B4XTable1.AddColumn("NEET MARKS", B4XTable1.COLUMN_TYPE_NUMBERS)'
B4XTable1.CreateDataView($"MAX${NumberColumn.SQLID}"$)
 
Solution
You need to first extract the max of the column in question and then use it in the CreateDataview: In one line:
B4X:
B4XTable1.CreateDataView($"${NumberColumn.SQLID} = (SELECT max(c0) FROM data)"$)  'better way
or in 2 lines below:
B4X:
Dim x As Int =B4XTable1.sql1.ExecQuerySingleResult($"SELECT max(c0) FROM data"$)  'c0 is 1st col, c1 is 2nd
        B4XTable1.CreateDataView($"${NumberColumn.SQLID} = ${x}"$)
If NumberColumn is 1st use c0 with max, if 3rd use c2, etc. If this does not solve it for you, export your project to forum.

Mahares

Expert
Licensed User
Longtime User
You need to first extract the max of the column in question and then use it in the CreateDataview: In one line:
B4X:
B4XTable1.CreateDataView($"${NumberColumn.SQLID} = (SELECT max(c0) FROM data)"$)  'better way
or in 2 lines below:
B4X:
Dim x As Int =B4XTable1.sql1.ExecQuerySingleResult($"SELECT max(c0) FROM data"$)  'c0 is 1st col, c1 is 2nd
        B4XTable1.CreateDataView($"${NumberColumn.SQLID} = ${x}"$)
If NumberColumn is 1st use c0 with max, if 3rd use c2, etc. If this does not solve it for you, export your project to forum.
 
Upvote 2
Solution

GJREDITOR

Member
You need to first extract the max of the column in question and then use it in the CreateDataview: In one line:
B4X:
B4XTable1.CreateDataView($"${NumberColumn.SQLID} = (SELECT max(c0) FROM data)"$)  'better way
or in 2 lines below:
B4X:
Dim x As Int =B4XTable1.sql1.ExecQuerySingleResult($"SELECT max(c0) FROM data"$)  'c0 is 1st col, c1 is 2nd
        B4XTable1.CreateDataView($"${NumberColumn.SQLID} = ${x}"$)
If NumberColumn is 1st use c0 with max, if 3rd use c2, etc. If this does not solve it for you, export your project to forum.
Thank you, Mahares. Works perfectly. I assume the 'data' is the db name created by B4Xtable library internally?
 
Upvote 0
Top