所以,我有以下表格:
使用LLBLGen 2.6(适配器版本 - No Linq),SQL Server和.NET 3.5,如何编写以下查询?
SELECT o.ObjectID
FROM Object o
INNER JOIN ObjectDetail d ON i.ObjectID = d.ObjectID
WHERE d.CreatedDate = ( SELECT MAX(CreatedDate)
FROM ObjectDetail
WHERE ObjectID = o.ObjectID
)
会有更多过滤,但它与此无关,就像我有一个 ObjectDetailType 并且我想要特定类型的max ObjectDetail 行。
此外,它不必选择 o.ObjectID ,任何/所有列都可以。
答案 0 :(得分:5)
解决了它
PredicateExpression.AddWithAnd(
new FieldCompareSetPredicate(
ObjectDetailFields.CreatedDate,
null,
ObjectDetailFields.CreatedDate.SetAggregateFunction(AggregateFunction.Max),
null,
SetOperator.Equal,
(ObjectFields.ObjectID == ObjectDetailsFields.ObjectID)
)
);