【发布时间】:2012-05-13 19:57:30
【问题描述】:
我有两个对象,一个房间类型和一个预订。简化为:
class Room {
String description
int quantity
}
class Reservation {
String who
Room room
}
我想查询所有房间以及每种类型的可用房间数量。在 SQL 中,这是我想要的:
select id, quantity, occupied, quantity-coalesce(occupied, 0) as available
from room left join(select room_id, count(room_id) as occupied from reservation)
on id = room_id;
我无处可寻,想知道如何用 HQL 做到这一点。
我会很感激任何指点,因为我似乎在 HQL 或 GORM 中遗漏了一些相当基本的东西。
【问题讨论】:
标签: grails hql grails-orm