我必须使用SUM 3列并在结果中返回值。写这个的正确方法是什么?
SubSonic.SqlQuery qs =new SubSonic.Select()
.From(Table.ViewAllratingsGlo.Schema.TableName);
SubSonic.Aggregate ag = SubSonic.Aggregate.Sum(("Column1+Column2+Column3), "Score");
qs.Aggregates.Add(ag);
string SqlResult = qs.BuildSqlStatement();
在SqlResult
我只看到像
Select SUM("Column1+Column2+Column3) As 'Score'
但我也需要我桌子上的其他字段。
答案 0 :(得分:1)
在这种查询中,select语句中的所有列都需要是聚合对象,只需将聚合类型更改为group by而不是sum。
SubSonic.SqlQuery qs = new Select(
new SubSonic.Aggregate("column1+column2+column3", "Score", AggregateFunction.Sum), //the original
new SubSonic.Aggregate(TableName.Column4, AggregateFunction.GroupBy), //another column
new SubSonic.Aggregate(TableName.Column5, AggregateFunction.GroupBy) //another column
)
.From(Table.ViewAllratingsGlo.Schema.TableName);