Android Question DBUtils SQL syntax

Declan

Well-Known Member
Licensed User
Longtime User
Please could someone help with the following SQL syntax issue.
I have a SQLite table and the following works great:
B4X:
Sub ShowSalesAll
    Dim Query As String
    Query = "SELECT barcode As [BARCODE], description As [PRODUCT], units As [SALES], date As [LAST SALES DATE] FROM transactions ORDER BY description"
    wbvManagerSales.LoadHtml(ExecuteHtml(SQL1, Query, Null, 0, True))   
End Sub
The WebView table populates great and shows all products and their data.
Now I need to be able to obtain the SUM of each product using the "Barcode" field as the filter.
I have tried:
B4X:
Sub ShowSalesAllTotals
    Dim Query As String
    Query = "SELECT DISTINCT barcode As [BARCODE], description As [PRODUCT], SUM(units) As [SALES], date As [LAST SALES DATE] FROM transactions WHERE units <> '0' ORDER BY description"
    wbvManagerSales.LoadHtml(ExecuteHtml(SQL1, Query, Null, 0, True))   
End Sub
But I only get 1 record from the table.
 

Declan

Well-Known Member
Licensed User
Longtime User
Thanks, this works:
B4X:
Query = "SELECT barcode As [BARCODE], description As [PRODUCT], SUM(units) As [TOTAL SALES], date As [LAST SALES DATE] FROM transactions group by barcode"
 
Upvote 0

Similar Threads

Top