English 中文(简体)
Grouping with SubSonic 3
原标题:

I have the following table "GroupPriority":

Id   Group   Priority
 1       1         0
 2       2         0
 3       3         0
 4       2         1
 5       1         1
 6       2         2
 7       3         1

I would like to group these on "Group", order them by "Priority" and then get the one in each "Group" with the highest Priority with the use of linq and subsonic 3.

In this case the result would be:

Id   Group   Priority
 5       1          1
 6       2          2
 7       3          1

The sql would look like this:

SELECT *
FROM   GroupPriority
WHERE  (Priority =
                  (SELECT  MAX(Priority)
                   FROM    GroupPriority
                   WHERE   (Group = GroupPriority.Group)))

Thanks

最佳回答

Got the solution:

    var group_query = new Query<GroupPriority>(provider);
    var items = from gp in group_query
                where gp.Priority == 
                    (from gp_sub in group_query
                     where gp_sub.Group == gp.Group
                     select gp_sub.Priority).Max()
                select gp;
问题回答

暂无回答




相关问题
wpf-DragDrop in a listbox with groupstyle

I am using the control library from http://code.google.com/p/gong-wpf-dragdrop/successfully for my listbox dragging operation.But there is an issue when i drop an item to a listbox with a group style....

Combine pairs to groups [PHP / Arrays]

I have pairs of items in an PHP array. Example: <?php $elements = array( tiger => lion , car => bike , lion => zoo , truck => plane ); ?> Now I want to combine ...

LINQ Merging results in rows

I have a LINQ query which returns a set of rows. The structure is: NAME, col1, col2, col3, col4 name1 1 null null null name1 null 1 null null name1 null null 1 1 As a ...

How to group items by date range in XSLT?

I have a bunch of data that looks a little like this: <item> <colour>Red</colour> <date_created>2009-10-10 12:01:55</date_created> <date_sold>2009-10-20 22:...

Self-Joins, Cross-Joins and Grouping

I ve got a table of temperature samples over time from several sources and I want to find the minimum, maximum, and average temperatures across all sources at set time intervals. At first glance this ...

Grouping with SubSonic 3

I have the following table "GroupPriority": Id Group Priority 1 1 0 2 2 0 3 3 0 4 2 1 5 1 1 6 2 2 7 ...

热门标签