1

私はステータスを持つクラスを持っています:

class A{
  String status
}

このステータスには、「開始」、「終了」、「進行中」の値があります。

1 つのクエリで「開始」、「終了」、および「進行中」の数を取得したいと思います。

この投稿を見ました:1つのクエリで異なるレコード数の値ですが、それはOracle専用です。

Grails/GORM でそれを行うことは可能ですか?

ありがとう。

4

2 に答える 2

4

使用できますexecuteQuery

def counts = A.executeQuery(
    'select status, count(status) from A group by status')

これは Object[] のリストを返します。

for (row in counts) {
    println "there are ${row[1]} with status '${row[0]}'"
}
于 2011-02-20T19:53:58.207 に答える
2

基準クエリが好きなら、これを見てください: stackoverflow->Using groupProperty and countDistinct in Grails Criteria

于 2011-02-21T08:54:16.750 に答える