【发布时间】:2020-06-29 06:08:09
【问题描述】:
我对如何在 this 的 select 和 where 子句中处理 IFNULL() 感到困惑。
我知道 HQL 提供了 COALESCE() 但我不确定如何继续 w.r.t。标准。
sql.eachRow("""SELECT DISTINCT cl.name, b.title, b.type, cb.region, IFNULL(cb.start, c.start),IFNULL(cb.end, c.end)
FROM table.C_B cb
JOIN table.B b on b.id = cb.B_id
JOIN table.C c on c.id = cb.C_id
JOIN table.CL cl on cl.id = c.CL_id
WHERE cb.status='active' AND
DATEDIFF(IFNULL(cb.start, c.start),'""" + startmonth + """') <=0
AND DATEDIFF(IFNULL(cb.end, c.end),'""" + startmonth + """') >0 order by cl.name, b.title"""
) {row ->
str.append('<tr>')
(0..3).each {str.append('<td>' + row[it] + '</td>')}
(4..5).each {str.append('<td>' + String.format('%tY/%<tm/%<td', row[it]) + '</td>')}
str.append('</tr>')
}
sqlProjection 是前进的方向吗?
【问题讨论】:
标签: hibernate grails grails-orm