mardi 27 janvier 2015

Android SQLite select SUM, GROUP BY

with this query I get the data from two tables. I used "GROUP BY" to group identical strings and display them in a ListView. The data is grouped correctly, but the "SUM" appears not to work, I get the sums wrong. For example, these are the data that I have to get



record1 = 100
record2 = 100
record3 = 100


instead I get



record1 = 300
record2 = 500
record3 = 200


I did several tests, but I can not get the correct dat



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

Aucun commentaire:

Enregistrer un commentaire