找到你要的答案

Q:Ebean - OrderBy with multiple columns

Q:ebean -与多个列进行排序

Update : Solution found. Problem was somewhere else in my code.

I'm using Ebean with Play Framework and I'm stuck with a query witch as orderBy clause on two columns. The first column is a varchar and the second one is a datetime.

The problem is when I add the second column in the orderBy clause, I can't sort anymore on the first one.

I have tried with the Ebean query way and the RawSQL way but the problem is still here.

Here are the lines of code I have tried :

Ebean.createQuery(NavGav.class).where().in("account.itemState", Account.getActiveStates()).between("navGavDate", "2015-01-01 00:00:00", "2015-12-31 23:59:59").orderBy(orderBy + " " + sort + ", navGavDate").findPagingList(ITEM_BY_PAGE * 12);

RawSql :

select columns
from nav_gav t0 left outer join account t1 on t1.id = t0.account_id where t1.item_state in ('VALIDATED', 'PENDING_DEACTIVATION', 'UPDATED')
order By t0.nav_frequency desc , t0.nav_gav_date

The query works on phpMyAdmin but not in the application.

Can you tell me what am I doing wrong?

Thanks.

更新:找到解决方案。问题在我的代码的其他地方。

我用ebean游戏框架,我只能查询女巫orderby子句在两列。第一列是varchar和第二个日期时间。

问题是,当我加入第二列在orderby子句,我不能再在第一个排序。

我已经尝试用ebean查询方式和rawsql方式但问题仍然在这里。

下面是我尝试过的代码行:

Ebean.createQuery(NavGav.class).where().in("account.itemState", Account.getActiveStates()).between("navGavDate", "2015-01-01 00:00:00", "2015-12-31 23:59:59").orderBy(orderBy + " " + sort + ", navGavDate").findPagingList(ITEM_BY_PAGE * 12);

RawSql:

select columns
from nav_gav t0 left outer join account t1 on t1.id = t0.account_id where t1.item_state in ('VALIDATED', 'PENDING_DEACTIVATION', 'UPDATED')
order By t0.nav_frequency desc , t0.nav_gav_date

查询的工作而不是在应用phpMyAdmin。

你能告诉我我做错了什么吗?

谢谢.

answer1: 回答1:

Please try not to concatenate the ordeyBy(column) method. try this.

 Ebean.createQuery(NavGav.class)
                .where().in("account.itemState", Account.getActiveStates())
                .between("navGavDate", "2015-01-01 00:00:00", "2015-12-31 23:59:59")
                .orderBy(orderBy + " " + sort)
                .orderBy(navGavDate + " " + sort)
                .findPagingList(ITEM_BY_PAGE * 12);

请不要将ordeyby(柱)的方法。试试这个。

 Ebean.createQuery(NavGav.class)
                .where().in("account.itemState", Account.getActiveStates())
                .between("navGavDate", "2015-01-01 00:00:00", "2015-12-31 23:59:59")
                .orderBy(orderBy + " " + sort)
                .orderBy(navGavDate + " " + sort)
                .findPagingList(ITEM_BY_PAGE * 12);
mysql  sql  playframework  ebean