Ormlite select count (*) as typeCount by type

I want to do something like this in OrmLite

SELECT *, COUNT(title) as titleCount from table1 group by title;

Is there a way to do this with QueryBuilder without queryRaw?

+4
source share
2 answers

The documentation states that using COUNT (), etc. requires use selectRaw(). I was hoping to get around this - no need to write my own SQL, because rows are the main reason I decided to use ORMLite.

http://ormlite.com/docs/query-builder

selectRaw (String... columns):
(COUNT, MAX,...) . - . , . . " " .

selectRaw(), :

, selectRaw(), " " , queryRaw().

, , , , , selectColumns() selectRaw() ( ) selectRaw() selectColumns() "" selectColumns(), .

, ORMLite selectRaw() , selectColumns().

QueryBuilder<EmailMessage, String> qb = emailDao.queryBuilder();
qb.selectColumns("emailAddress"); // This column is not selected due to later use of selectRaw()!
qb.selectRaw("COUNT (emailAddress)");

ORMLite , , , :

QueryBuilder<EmailMessage, String> qb = emailDao.queryBuilder();        
qb.selectRaw("emailAddress"); // This can also be done with a single call to selectRaw()
qb.selectRaw("COUNT (emailAddress)");
qb.groupBy("emailAddress");
GenericRawResults<String[]> rawResults = qb.queryRaw(); // Returns results with two columns
+1

QueryBuilder queryRaw(...)?

- , ORMLite , . Table1 DAO, COUNT(title)? , .

(v5.1) custom RawRowMapper, dao.getRawRowMapper() method Table1 titleCount .

, ORMLite. .

0

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


All Articles