【问题标题】:Query with SUM using SubSonic使用 SubSonic 进行 SUM 查询
【发布时间】:2009-05-08 07:27:59
【问题描述】:

我是Subsonic新手,想问一下SUM怎么查询?

我知道如何查询 where 条件如下:

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();
}

但是如何用 SUM 查询呢?

谢谢! 哈利姆

【问题讨论】:

    标签: c# subsonic sum


    【解决方案1】:

    这是一种方法:

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

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

    【讨论】:

      【解决方案2】:

      如果您想使用 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();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多