三个表上的 Ormlite 内连接

发布于 2024-12-02 18:55:03 字数 371 浏览 1 评论 0原文

我想在三个表上创建一个内部联接,例如:

SELECT C.Description, D.ItemDescription
  FROM OrderDetailStatement AS D 
 INNER JOIN OrderHeaderStatement AS H 
    ON H.OrderHeaderStatementRefID = D.OrderHeaderStatementRefID 
 INNER JOIN customers AS C 
    ON H.CustomerRefID = C.CustomerRefID
 WHERE (D.MixedValue > 1000)

但我有点困惑,你能给我一个演练吗?

提前致谢

i want to create an inner join on three tables like this one for example:

SELECT C.Description, D.ItemDescription
  FROM OrderDetailStatement AS D 
 INNER JOIN OrderHeaderStatement AS H 
    ON H.OrderHeaderStatementRefID = D.OrderHeaderStatementRefID 
 INNER JOIN customers AS C 
    ON H.CustomerRefID = C.CustomerRefID
 WHERE (D.MixedValue > 1000)

but i'm a little bit confused, could you please provide me a walkthrough?

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故笙诉离歌 2024-12-09 18:55:03

ORMLite 现在支持简单的JOIN 声明。您可以执行如下操作:

// start the order header query
QueryBuilder<OrderHeader, Integer> orderHeaderQb = orderHeaderDao.queryBuilder();
QueryBuilder<Customer, Integer> customerQb = customerDao.queryBuilder();
// join with the order query
orderHeaderQb.join(customerQb);
// start the order statement query
QueryBuilder<OrderStatement, Integer> orderStatementQb =
    orderStatementDao.queryBuilder();
orderStatementQb.where().gt("mixedvalue", 100);
// join with the order-header query
orderStatementQb.join(orderHeaderQb);
List<OrderStatement> orderStatementQb.query();

但是请注意,您只能使用此机制从查询生成器获取实体。如果您想从不同的对象获取两个描述字段,那么您仍然必须使用原始查询。

支持“原始查询”,包括 Dao.queryRaw() 方法,您可以在其中使用自己的 SQL。我怀疑你已经找到它们了。以下是原始查询文档

ORMLite now supports simple JOIN statements. You can do something like the following:

// start the order header query
QueryBuilder<OrderHeader, Integer> orderHeaderQb = orderHeaderDao.queryBuilder();
QueryBuilder<Customer, Integer> customerQb = customerDao.queryBuilder();
// join with the order query
orderHeaderQb.join(customerQb);
// start the order statement query
QueryBuilder<OrderStatement, Integer> orderStatementQb =
    orderStatementDao.queryBuilder();
orderStatementQb.where().gt("mixedvalue", 100);
// join with the order-header query
orderStatementQb.join(orderHeaderQb);
List<OrderStatement> orderStatementQb.query();

Notice, however, that you can only get entities from the query builder using this mechanism. If you want to get your two description fields from different objects then you would have to still use a raw-query.

There is support for "raw queries" including the Dao.queryRaw() method where you can use your own SQL. I suspect you've found them already. Here are the docs for raw queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文