mercredi 28 janvier 2015

Android SQLite LeftJoin

I do not understand the behavior of this query, that is: I want to sum a field from a table with different clauses and display them in a ListView. Fields are returned in the right way, but the sum of the largest value is done 4 times for herself.


For example, the query returns me:



fiat 4.000
bmw 300
audi 200
ferrari 500


instead it should return:



fiat 1.000
bmw 300
audi 200
ferrari 500


the query:



String sql = "SELECT DISTINCT r.nome_categoria, r.colore_testo, c._id, c.categoria, SUM(c.spesa) FROM Auto c LEFT JOIN" +
" Categorie r ON (c.categoria = r.nome_categoria) WHERE c.spesa>0 AND c.data LIKE '"+anno+"-"+mese_ric+"%' GROUP BY r.nome_categoria ORDER BY SUM(c.spesa) DESC";

Aucun commentaire:

Enregistrer un commentaire