gpt4 book ai didi

java - JPQL Eclipselink - 如何连接两个表并显示另一个表中没有项目的项目

转载 作者:行者123 更新时间:2023-12-01 11:59:26 27 4
gpt4 key购买 nike

我尝试选择所有根本没有出价的订单,但出现异常,我该怎么做?

这就是我想做的:

SELECT o, COUNT(b) FROM OrderEntity o LEFT JOIN OrderBidEntity b ON o.id = b.orderId WHERE COUNT(b) = 0 AND o.created < :date ORDER BY o.created ASC

Exception in thread "Thread-4" java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [SELECT o, COUNT(b) FROM OrderEntity o LEFT JOIN OrderBidEntity b ON o.id = b.orderId WHERE COUNT(b) = 0 AND o.created < :date ORDER BY o.created ASC].
[91, 99] The COUNT function is only allowed in the SELECT, GROUP BY, ORDER BY and HAVING clauses.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:342)
at com.sun.proxy.$Proxy38.createQuery(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce

最佳答案

我目前无法仔细检查这一点,但错误消息非常具有描述性。您可以尝试调整您的查询,如下所示:

SELECT o FROM OrderEntity o WHERE (SELECT COUNT(b) FROM OrderBidEntity b WHERE o.id = b.orderId) = 0 AND o.created < :date ORDER BY o.created ASC

关于java - JPQL Eclipselink - 如何连接两个表并显示另一个表中没有项目的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28093740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com