我正在尝试将以下 SQL 转换为 Esqueleto:
SELECT id, task_id, author_id
FROM scenario
INNER JOIN ( SELECT task_id as tId, author_id as aId, MAX(last_update) as lastUp
FROM scenario
GROUP BY task_id, author_id
) t
ON task_id = tId AND author_id = aId AND last_update = lastUp
要进行子查询,您必须使用subList_select。
我想不出一种将它与模式匹配相结合的方法:
from $ \(s `InnerJoin` ?subQueryhere?) -> do ...
所以我改为尝试where_
:
where_ (s ^. ScenarioTaskId ==. (subList_select $
from $ \s' -> do
groupBy (s' ^. ScenarioTaskId, s' ^. ScenarioAuthorId)
return s'
) ^. ScenarioTaskId)
但是,这不会编译,因为subList_select
返回 aexpr (ValueList a)
而不是 a expr (Entity Scenario)
。