tags:

views:

42

answers:

1

Hello, I'm creating a simple query with aggregates. The example is:

string query = new SubSonic.Query.Select(
      SubSonic.Query.Aggregate.GroupBy("ProductID", "ID"),
      SubSonic.Query.Aggregate.Max("Price", "MaxPrice")
   ).From("Orders").ToString();

The Sql Result is:

SELECT ProductID AS ID, MAX(Price) AS MaxPrice
FROM [Orders]

when the result must be:

SELECT ProductID AS ID, MAX(Price) AS MaxPrice
FROM [Orders]
GROUP BY ProductID

In SubSonic2.2 the result is correct but in Subsonic3 , the GROUP BY statement dissapear and the query return only one row.

Is correct my SqlQuery expression? or is a bug in Subsonic3? I'm using Subsonic 3.0.0.3.

Thank you!!

A: 

Not entirely sure about the exact syntax, I use the

MyTableClass.All().Max

Notation for querying it.Your example looks wrong though, because your groupBy is inside your select. The groupBy is not part of the select, so maybe you need to move that GroupBy outside your select

Matt Roberts
thanks for replying, but I need the max price for each product.I can rewrite the query: SqlQuery query1 = new Select().From("Orders"); query1.Aggregates = new List<Aggregate> { new Aggregate("ProductID", "ID", AggregateFunction.GroupBy), new Aggregate("Price", AggregateFunction.Max)}; MessageBox.Show(query1.ToString());but the same result again, I need the 'GROUP BY ProductID' sql clause to obtain the max price for every product.
aris
the problem is that the SqlQuery don't generates the 'GROUP BY ProductID' part in SQL query
aris