linq 多表分组查询统计
var q1 = from orderitem in q2
join pd in _iProductDetailContract.Entities on orderitem.ProductDetailId equals pd.Id
join pm in ProductMainContract.Entities on pd.ProductMainId equals pm.Id
join user in UserContract.Entities on pm.BuyerId equals user.Id
into orderItemBuyer
from user in orderItemBuyer.DefaultIfEmpty()
group new { orderitem.Price, orderitem.Num }
by new { orderitem.ProductDetailId, orderitem.Name, orderitem.Size, orderitem.Price, pm.AliasName, BuyerName = user.Name }
into g
orderby g.Sum(p => p.Num) descending
select new
{
ProductDetailId = g.Key.ProductDetailId,
Name = g.Key.Name,
Size = g.Key.Size,
AliasName = g.Key.AliasName,
BuyerName = g.Key.BuyerName,
Num = g.Sum(p => p.Num),
Price = g.Key.Price,
TotlePrice = g.Sum(p => p.Num * p.Price)
}
;
linq 多表分组查询统计的更多相关文章
- rails小技巧之分组查询统计并去重
分组查询并统计 SpecialGroup.group(:special_type).count select special_type,count(*) from special_groups gro ...
- 借助case,实现更丰富的分组查询统计
根据fileD6的前4位分组 分别统计该组 5种企业类型fileD31的数量 create or replace view jyjc_bycity as select substr(fileD ...
- Linq分组查询统计
这里介绍Linq使用Group By和Count得到每个CategoryID中产品的数量,Linq使用Group By和Count得到每个CategoryID中断货产品的数量等方面. 学经常会遇到Li ...
- Linq 多表连接查询join
在查询语言中,通常需要使用联接操作.在 LINQ 中,可以通过 join 子句实现联接操作.join 子句可以将来自不同源序列,并且在对象模型中没有直接关系(数据库表之间没有关系)的元素相关联,唯一的 ...
- MySQL分组查询统计
GROUP BY 1.有个店铺表,字段为区域id,设备数量,店铺名称,如下: 2.如何按区域 district 统计 每个区域的设备数量,SQL如下 SELECT district, SUM( dev ...
- linq to EF分组查询 group by 的使用
第一种:查询表达式语法: IQueryable<EnrollmentDateGroup> data = from student in db.Students group student ...
- oracle-按年、月、周、日、时、分 分组查询统计数据,无数据补零(connect by)
目的:统计一段时间内每年.每月.每周.每日.每时.每分数据,无数据时自动补零 思路:1. 生成给定时间段对应日期 2. 将原表中该时间段内的不为0的数据量统计出来 3. 用left join连接起来, ...
- linq 中的分组查询
直接看代码: //一个字段分组 var data1 = from a in query group a by a.Name into b select new { Total = b.Sum(c=&g ...
- Linq多表联合查询,在View中绑定数据
Ⅰ→通过ViewData传递数据,不过需要新建一个类(用来存) NewClass(里面有表1的字段和表2的字段) public class JoinTab1_2 { public int ID { g ...
随机推荐
- WPF 资源字典【转】
使用好处:存储需要被本地话的内容(错误消息字符串等,实现软编码),减少重复的代码,重用样式,实现多个项目之间的共享资源;修改一个地方所有引用的地方都会被修改,方便统一风格;使用方法,归纳起来主要有下面 ...
- mysql-异常
1.Subquery returns more than 1 row 返回的集合应该是一条才能用,但你返回了多条.
- dede使用方法----更换模板
刚开始接触dede的时候,自己一直在纠结怎么更换自己的模板啊.后面在秀站网上找到了一个比较好的更换模板的文字教程.下面就我自己做的进行写的笔记. 准备:一个你自己做好的静态版网站,我们假设它的名称是w ...
- 「个人vim插件+配置」
2016.10.4 filetype indent on syntax on set nu ai ci si set sw= ts= set autochdir set backspace= colo ...
- bzoj4337: BJOI2015 树的同构
hash大法好 #include <iostream> #include <cstdio> #include <cstring> #include <cmat ...
- the comment lines of the blast tabular format
进行Blast比对,用参数-m 6 可以以列表的方式输出结果,结果中从左到右每一列的意义分别是: [00] Query id [01] Subject id [02] % identity [03] ...
- 【matlab】设定函数默认参数
C++/java/python系列的语言,函数可以有默认值,通常类似如下的形式: funtion_name (param1, param2=default_value, ...) 到了matlab下发 ...
- hdu1402 FFT入门
参考这里:http://www.cnblogs.com/pdev/p/4354705.html http://www.cnblogs.com/pdev/p/4354629.html 题意:求大数乘法 ...
- [NOIP2013] 普及组
计数问题 纯模拟 #include<cstdio> #include<iostream> using namespace std; int main(){ int n,x; c ...
- Linux UserSpace Back-Door、Rootkit SSH/PAM Backdoor Attack And Defensive Tchnology
catalog . 引言 . Pam后门 . SSH后门 . Hijacking SSH . Hijacking SSH By Setup A Tunnel Which Allows Multiple ...