【发布时间】:2013-06-28 18:33:46
【问题描述】:
我正在尝试执行查询以收集特定数据,但在查询的 on 部分遇到问题。首先这是我的课:
class TimeSlot {
String timeslot_id
String time_chunk_id
String uid
String exam_id
String start_time
String is_special_arrangement
static mapping = {
table 'timeslot'
id name: "timeslot_id", column: "timeslot_id"
version false
}
}
这是我正在尝试的查询:
TimeSlot.executeQuery("Select t.time_chunk_id, t.uid, t.start_time, t.timeslot_id, t.is_special_arrangement, e.length from TimeSlot t inner join Exams e on t.exam_id = e.exam_id where t.exam_id = ? and t.time_chunk_id = ?", [testArray[i], timeChunkArray[x]])
它在on 部分引发错误,因为它需要一个子句,但我需要数据专门与两个表的exam.id 比较有关。是否有其他方法或不同的方法来设置查询,使其能够像在任何 SQL 编辑器中一样工作?
【问题讨论】:
-
在查询中使用
with而不是on。 HQL 不支持on关键字。它的等价物是with。 -
这消除了错误,但现在它说 in can't resolve the symbol
tatt.exam_id = e.exam_id.关于为什么会发生这种情况的任何建议? -
使用
from TimeSlot as T, Exams as e where t.exam_id = e.exam_id。 -
我试图不将其拆分为两个不同的查询,因为它不会产生与我当前尝试使用的特定查询相关的相同结果。
-
如果您还不知道,可以将域对象映射到
exam_id列。就像exams column: exam_id在TimeSlot里面一样,考试是Exams