我有以下工作SQL查询:
SELECT count(*) FROM A a LEFT OUTER JOIN B b ON a.id = b.aid AND a.x = 700 AND b.y = 800 WHERE a.type = 1 AND b.type = 2;
我想使用等效的HQL。
我已经尝试了以下但是它不起作用(编译):
SELECT count(*) FROM A AS a LEFT JOIN B AS b AND a.x = 700 AND b.y = 800 WHERE a.type = 1 AND b.type = 2;
没有“和a.x = 700和b.y = 800”部分它可以正常工作。
你能告诉我吗?
P.S。 我需要在“where”之前使用“and a.x = 700和b.y = 800”部分,因为它被索引并且已经分区,我需要在连接期间使用索引和分区。
感谢名单, 保尔。
您好,
似乎我的问题比通常情况更复杂,所以我只会发布确切的代码:
@Entity
@AttributeOverride(name = "id", column = @Column(name = HFrEvent.COL_EVENT_ID))
@Table(name = HFrEvent.TBL_HFREVENT)
public class HFrEvent extends HOrgEntity {
..
@OneToMany(fetch = FetchType.EAGER)
@Cascade({ org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@JoinColumn(name = COL_EVENT_ID)
public List<HFrEventKeys> getEventKeys() {
return eventKeys;
}
..
}
@Entity
@Table(name = "HFREVENTKEYS")
public class HFrEventKeys extends HOrgEntity {
..
}
以下查询有效,但没有明确的“on”语句: 从HFrEvent中选择count(事件)作为事件左连接event.eventKeys作为键,其中event.orgFields.customerId = 110 AND event.orgFields.institutionId = 121 and key.orgFields.customerId = 110 AND key.orgFields.institutionId = 121 and key .name =:name和key.value =:value和event.eventType = 1113;
我想将一些customerid和systemid移动到连接部分。
以下不编译:
SELECT count(event)
FROM HFrEvent AS event
LEFT JOIN event.eventKeys AS key
ON event.orgFields.customerId = 110
AND event.orgFields.institutionId = 121
AND key.orgFields.customerId = 110
AND key.orgFields.institutionId = 121
WHERE key.name=:name
AND key.value=:value
AND event.eventType = 1113;
谢谢你,
保尔。