【问题标题】:Ebean - OrderBy with multiple columnsEbean - 具有多列的 OrderBy
【发布时间】:2015-10-08 10:31:20
【问题描述】:

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

我正在将 Ebean 与 Play Framework 一起使用,但我在两列上使用了一个查询女巫作为 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 上有效,但在应用程序中无效。

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

谢谢。

【问题讨论】:

  • 更新:发现问题。它在我的代码中的其他地方。上面的代码工作正常。

标签: mysql sql playframework ebean


【解决方案1】:

请尽量不要连接ordeyBy(column) 方法。试试这个。

 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);

【讨论】:

  • 设置 orderBy(...) 两次将覆盖第一个 orderBy(...)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 2016-07-21
  • 2015-09-08
相关资源
最近更新 更多