Complex query with SQL COUNT and SUM

I am trying to create the following query in Ormlite:

SELECT Column1,
      COUNT(Column2),SUM(Column2)

  FROM Table

  WHERE Column3 = 1

  GROUP BY Column1;

I use QueryBuilder for this, but I cannot figure out how to get the amount and still have one complete list as a result.

What will be the type of this list of results? I cannot do this List, since the sum and number of columns are not columns in the table.

+4
source share
2 answers

I use QueryBuilder for this, but I cannot figure out how to get the amount and still have one complete list as a result.

COUNT SUM, , . .

:

http://ormlite.com/docs/raw-queries

+2

QueryBuilder<UsageStats, Integer> b = dao.queryBuilder();
b.selectRaw("SUM(" + UsageStats.COLUMN_VALUE + ")");
b.groupBy(UsageStats.COLUMN_TYPE);
b.where().eq(UsageStats.COLUMN_TYPE, type.toString());
dao.queryRawValue(b.prepareStatementString());
+4

Source: https://habr.com/ru/post/1526948/


All Articles