ORMLITE ORDER_BY with multiple columns

本小妞迷上赌 提交于 2019-12-21 07:05:00

问题


I am using ormlite in my recent android project. I want to order by on a query on multiple columns in a table (say two columns). How can I achieve that??

Here is the code for a single order by...

QueryBuilder<Visit, Integer> qb = getHelper().getVisitDao().queryBuilder();
qb.where().eq("FOREIGN_ID", id);
qb.orderBy("VISIT_DATE", false);

回答1:


I want to order by on a query on multiple columns in a table(say two columns). How can i achieve that??

All you need to do is to call orderBy(...) multiple times.

qb.orderBy("VISIT_DATE", false);
qb.orderBy("order-column", false);
...

This is covered by the documentation. To quote:

Add "ORDER BY" clause to the SQL query statement to order the results by the specified column name. Use the ascending boolean to get a ascending or descending order. This can be called multiple times to group by multiple columns.

Also the javadocs:

Add "ORDER BY" clause to the SQL query statement. This can be called multiple times to add additional "ORDER BY" clauses. Ones earlier are applied first.



来源:https://stackoverflow.com/questions/15666847/ormlite-order-by-with-multiple-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!