Just when I thought I have a good handle on SQLite, I do not. My goal is to display the most recent record of every PROD_WELL.
1. I create a table:
2. I insert a number of records:
3. I run the below query:
The data needs to be sorted by PROD_DATE DESC, but if there are records with same PROD_DATE only the the record with the most recent date and most recent PROD_TIME needs displayed. In other words, ONLY one record per PROD_WELL needs to be. displayed.
I do not want to use any ticks, just the data as is
The query yields below but:this line should not be there: 6743,20170113,09:15,203
' 6743,20170113,12:35,145
' 6743,20170113,09:15,203
' 6900,20170317,10:45,109
' 8300,20170506,02:34,400
' 7345,20170610,09:15,539
1. I create a table:
B4X:
SQL1.ExecNonQuery("CREATE TABLE t1 (PROD_WELL TEXT , PROD_DATE TEXT, PROD_TIME TEXT, PROD_CSGP)")
B4X:
Dim MyQuery As String ="INSERT INTO t1 VALUES (?,?,?,?)"
SQL1.ExecNonQuery2(MyQuery, Array As String( "6743","20170113", "12:35", "145"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "6900","20170317", "10:45", "109"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "7345","20170610", "09:15", "539"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "6743","20170113", "09:15", "203"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "8300","20170506", "02:10", "491"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "6743","20170112", "13:35", "331"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "6900","20170317", "06:55", "109"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "8300","20170501", "02:47", "300"))
SQL1.ExecNonQuery2(MyQuery, Array As String( "8300","20170506", "02:34", "400"))
B4X:
MyQuery=$"SELECT * FROM t1 WHERE
PROD_DATE IN (SELECT Max(PROD_DATE) FROM t1 GROUP BY PROD_WELL )
AND
PROD_TIME IN (SELECT Max(PROD_TIME) FROM t1 GROUP BY PROD_WELL, PROD_DATE )
ORDER BY PROD_DATE, PROD_TIME DESC"$
I do not want to use any ticks, just the data as is
The query yields below but:this line should not be there: 6743,20170113,09:15,203
' 6743,20170113,12:35,145
' 6743,20170113,09:15,203
' 6900,20170317,10:45,109
' 8300,20170506,02:34,400
' 7345,20170610,09:15,539