解决了!我创建了一个 CRITERIA 函数来替换子查询。不优雅但有效!
def myList = []
String tempName = ""
int patPosition = 0
int myListPosition = -1
int find = 0
int maxOcc = 0
def c = Doctor.createCriteria()
def pat = c.list {
patients {
}
}
while(patPosition<pat.size()){
find=0
tempName=pat[patPosition].lastName //Some constraints to add
find=pat.lastName.count(tempName)
if(find>maxOcc){
maxOcc=find
}
myListPosition=myListPosition+1
myList[myListPosition]=find
patPosition=patPosition+find
}
print "\n\nLIST -> "+myList
print "MAX -> "+maxOcc
String queryToDo= "SELECT d.name, count(p) "+
"FROM Doctor as d INNER JOIN d.patients as p "+
"GROUP BY d.name "+
"HAVING count(p) = $maxOcc"
def query = Doctor.executeQuery(queryToDo)
render query