1

I'm new to Subsonic, I want to ask how to query with SUM?

I know how to query for where condition such as below:

Query qryCurOpcode = Station.CreateQuery()
    .WHERE("PRODLINE=PIECERATE_prodline")
    .AND("STATIONID=STNID")
    .AND("SHIFT=PIECERATE_shift");

IDataReader rdrCurOpcode = qryCurOpcode.ExecuteReader();

while (rdrCurOpcode.Read())
{
    PIECERATE_CurOpcode = rdrCurOpcode[Station.Columns.Curopcode].ToString();
}

but how to how to query with SUM?

Thanks! Halim

4

2 回答 2

2

这是一种方法:

int sum = (int)new Query("Station").GetSum("Shift");

您可以从以下获得更多示例: SubSonic Aggregate Queries

于 2009-05-08T07:59:59.870 回答
0

如果您想使用 sum 之类的聚合,那么最好的方法是使用 Subsonic 的聚合 :)。有关示例的完整列表,请查看SubSonicProject

以下是直接取自上面链接的一些示例。

 double result = new
    Select(Aggregate.Avg("UnitPrice"))
    .From(Product.Schema)
    .ExecuteScalar<double>();

 IDataReader reader = new
    Select(Aggregate.GroupBy("ProductID"), Aggregate.Avg("UnitPrice"))
    .From("Order Details")
    .Where(Aggregate.Avg("UnitPrice"))
    .IsGreaterThan(50)
    .ExecuteReader();
于 2009-05-08T15:17:02.120 回答