title: Android SQLite query group by and order by
body: <p>I insert data in a listview with the spinner and choose the year you want and visualize the data based on the selected date.
  Now I want to group the data by year and not separated by month.
  What should I change? this is the code:</p>
  
  <pre><code>private void showDetails(String anno){
      SQLiteDatabase db = new BilancioHelper(this).getReadableDatabase();
      final List&lt;Dettaglio&gt; dettagli = new ArrayList&lt;Elenco_cat_entrate.Dettaglio&gt;();
  
      for (int i=1; i&lt;=12; i++){
          String mese;
          if (i&lt;10){
              mese = "0"+i;
          } else {
              mese = ""+i;
          }
          String sql ="SELECT Categoria, SUM(Entrata) FROM Giornate WHERE entrata&gt;0 AND data LIKE '"+anno+"-%' GROUP BY Categoria";
          Cursor c = db.rawQuery(sql, null);
  
          while (c.moveToNext()){
              Dettaglio d = new Dettaglio();
  
              d.categorie = c.getString(0);
              d.entrate = c.getFloat(1);
  
  
              dettagli.add(d);
          }
          c.close();
      }
  
      db.close();
  
      ListAdapter adapter = new ArrayAdapter&lt;Dettaglio&gt;(this, R.layout.dettaglio_categorie_entrate, R.id.tv_totale_group, dettagli){
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              View row = super.getView(position, convertView, parent);
  
  
              TextView tvEntrata, tvCategoria;
              tvEntrata = (TextView) row.findViewById(R.id.tv_totale_group);
  
              tvCategoria = (TextView) row.findViewById(R.id.tv_categorie_group);
  
  
              Dettaglio d = dettagli.get(position);
  
              tvCategoria.setText(d.categorie+"");
              tvEntrata.setText(d.entrate+"");
  
              return row;
          }
      };
  
      lista.setAdapter(adapter);
  
  }
  </code></pre>