[英]LLBL GEN PRO 3.1 Select distinct two fields
Is it posible to use DefineField
and AggregateFunction.SumDistinct
with two fields in LLBL GenPro 3.1? 是否可以将
DefineField
和AggregateFunction.SumDistinct
与LLBL GenPro 3.1中的两个字段一起使用? For example I have this: 例如我有这个:
ResultsetFields myFields = new ResultsetFields(2);
//I want this amount to be distinct but with specific userId
myFields.DefineField(UserFields.Amount, 0, AggregateFunction.SumDistinct);
myFields.DefineField(UserFields.Id, 1, "ResultCount", AggregateFunction.CountDistinct);
In SQL, I want it end up with something like: 在SQL中,我希望它以类似以下内容结尾:
SELECT DISTINCT SUM(u.Amount), u.Id
FROM Users u
INNER JOIN someOtherTablesat ON sot.UserId = u.Id
GROUP BY
u.Id
This join I have in LLBL and it duplicates amount, because someOtherTable
has few data for same user. 我在LLBL中有此联接,它重复了数量,因为
someOtherTable
对于同一用户几乎没有数据。 I need that join for some another reason. 我需要加入另一个原因。 So, is it possible to do that with LLBL and how?
那么,使用LLBL可以做到这一点吗?
Finally I found solution: 最后我找到了解决方案:
var fields = new ResultsetFields(1);
fields.DefineField(OrderFields.Freight, 0, AggregateFunction.Sum);
var bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(new FieldCompareSetPredicate(
OrderFields.OrderId, null, OrderDetailFields.OrderId, null,
SetOperator.In, (OrderDetailFields.ProductId ==1)));
DataTable dynamicList = new DataTable();
using (var adapter = new DataAccessAdapter())
{
adapter.FetchTypedList(fields, dynamicList, bucket);
}
In SQL that is more like 在SQL中更像
Select SUM(Freight) from Orders
Where OrderID IN
(
Select OrderID from [Order Details] where ProductID = 1
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.