是否有可能是不存在的GROUPBY列订购? [英] Is it possible to order by column which is not present in groupby?

查看:90
本文介绍了是否有可能是不存在的GROUPBY列订购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有这样的查询:

For example , i have a query like this:

var data= from c in customers
          join o in orders
          on c.id=o.id
         group new { c, o } by new { o.customerid, c.FirstName, c.LastName, c.City } into customergroups
         orderby customergroup.select(x=>x.o.quantity)

但是, ..

请建议...

推荐答案

可以按任何顺序对组进行排序,只要表达式产生一个可比较的对象。例如,您可以按最小最大数量 * 进行排序,但不能只按数量排序,因为可能有许多不同的数量

Yes, it is possible to order your groups by anything, as long as the expression produces a comparable object. For example, you could order by the minimum or the maximum quantity *, but not by just quantity, because there may be many different quantities in a group.

var data= from c in customers
      join o in orders
      on c.id=o.id
     group new { c, o } by new { o.customerid, c.FirstName, c.LastName, c.City } into customergroups
     orderby customergroup.Max(x=>x.o.quantity);

* 您也可以使用 => xoquantity) Last(x => xoquantity),但顺序是任意的。

* You could also use First(x=>x.o.quantity) or Last(x=>x.o.quantity), but the order would be arbitrary.

这篇关于是否有可能是不存在的GROUPBY列订购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆