Grails sub query with createCriteria



我有如下sql查询

select transf, count(fname)  from peak_info where fname  in (select peakfile from pe_result where conid = 'GO:0006007' and fdr > 0.05) group by transf;

我想在圣杯中创建标准中实现。目前,我首先在括号中运行SQL查询,然后运行如下所示的外部查询:

 def test2 = PeResult.createCriteria()
        def ptest=test2.list {
            eq("conid",conid.toString())
            gt("fdr","0.05")
            }
def peaknames = ptest.peakfile
def peakinfoFilter = PeakInfo.createCriteria()
def pifilter = peakinfoFilter.list {

   'in'("fname", peaknames)


    projections
        {

           groupProperty "transF"

            count "fname"

        }


}

我想知道是否有其他方法可以在一个查询中执行此操作而不是运行两个查询?

你可能可以做这样的事情。没有执行它,但你明白了。看看 GORM 的子查询部分。

def peakinfoFilter = PeakInfo.createCriteria()
def pifilter = peakinfoFilter.list {
   'in' "fname", PeResult.where{
                  conid == conid.toString()
                  fdr > "0.05"
            }. peakfile
    
    projections
    {
       groupProperty "transF"
       count "fname"
    }
}

最新更新