Grails子查询

时间:2014-11-26 09:25:31

标签: mysql grails subquery gorm

我有一个mysql查询

SELECT a.* FROM table a,
        (SELECT NAME, MAX(VERSION) AS VERSION FROM table b
        WHERE b.version <= 2.3
        GROUP BY NAME ) c
        WHERE a.name=c.name
        AND a.version=c.version;

我想转换为grails查询。我试过并将其作为

Table.executeQuery("from Table a, (SELECT NAME, MAX(VERSION) FROM Table b WHERE b.VERSION <= :fieldVersion GROUP BY b.NAME) c where a.NAME=c.NAME AND a.VERSION=c.VERSION",[fieldVersion:version]);

但代码显示附近的错误,(SELECT 并且它不会编译。

2 个答案:

答案 0 :(得分:0)

试试这个..

Table.findAll(“from table as a,(SELECT NAME,MAX(VERSION)AS VERSION FROM table b WHERE b.version&lt; =? GROUP BY NAME)c WHERE a.name = c.name AND a.version = c.version“,[2.3])

答案 1 :(得分:0)

试试这个:

import groovy.sql.Sql

def executeQuery(String query) {
    def db = new Sql(dataSource)
    db.rows(query)
}

您返回的内容取决于查询本身