카운트 내 두 클래스으로 Grails 돌기에 의해 그룹과
class Users {
String emailAddress
String password
// String filename
String firstName
String lastName
Date dateCreated
Date lastUpdated
}
및
class SharedDocuments {
Users author
Users receiver
Documents file
static constraints = {
}
}
나는이 유사한 쿼리를 실행하려면
있으며, 기본적으로 내가 모든 사용자의 목록을 얻으려면 문서의 개수와 함께 그들은 이것은 내가 지금까지 이 무엇SELECT author_id, COUNT(SharedDocuments.id)FROM SharedDocuments
INNER JOIN users ON author_id = users.id
GROUP BY author_id
저술 한 내가 기여한 사용자의 목록을하지만 내가 원하는 것은 문서의 카운트와 함께 저자이다 count
또는 countDistinct
제거하면
def sharedDocumentsInstanceList = SharedDocuments.createCriteria().list(params){
createAlias("author","a")
eq("receiver.id",session.uid)
projections{
groupProperty "author"
count "id",'mycount'
}
order('mycount','desc')
maxResults(params.max)
}
나는,이 90 %의 작업이있다. 그래서 count 나 countDistinct 절을이 기준에 추가하면 배열이 길어집니다 !! 같은 는 [2,3,4]는 내가 원하는 어떻게 내가 이미 Grails: Projection on many tables?을 보았다이 achive, Grails criteria projections - get rows count, Grails groupProperty and order. How it works?, 수 있지만, [[author2,3] ... [author1,2]]입니다 없음 대답은 내 문제를 해결하는 것 같습니다!
내 결과 집합과 상관없이 단지 다른 정보가 없습니다. 당신이 내게 준 코드에서 sharedDocumentsInstanceList를 출력하면 '[2,]'출력이 나온다. – Sap
나는 똑같은 일을하고있다.하지만 maxResults가 없으면 명명 된 쿼리를 사용하면 괜찮다. author.id에서 그룹화하는 것은 너무 일해야합니다. –