1

如何在 ORMLite 中实现这个 SQL 查询并评估结果?

SELECT SUM(column1 * column2) AS total FROM (ANOTHER_SELECT_QUERY)
4

1 回答 1

2

Couple different ways to do this. One way would be the simple:

long sum = dao.queryRawValue(
        "SELECT SUM(column1 * column2) AS total FROM (...)");

You can use the QueryBuilder to build the query.

QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
qb.selectRaw("SUM(column1 * column2) AS total");
qb.where()...
long sum = dao.queryRawValue(qb.prepareStatementString());

I don't think you need to have the inner since column1 and column2 I assume are in the inner query and the WHERE can be just moved to the outer query.

于 2012-11-05T19:45:46.873 回答