我只想改变这个:
Period | Department | Print | Copy
---------------------------------------
201601 | Dept 1 | 10 | 20
201601 | Dept 2 | 20 | 10
201602 | Dept 1 | 30 | 40
201602 | Dept 2 | 40 | 30
201603 | Dept 1 | 50 | 60
201603 | Dept 2 | 60 | 50
Run Code Online (Sandbox Code Playgroud)
进入这个:
Department | 201601 Print | 201601 Copy | 201602 Print | 201602 Copy | 201603 Print | 201603 Copy
------------------------------------------------------------------------------------------
Dept 1 …Run Code Online (Sandbox Code Playgroud) 我有一个模型“水果”存储这样的数据:
date fruit_code count
2013/09/30 apple 10
2013/09/30 pear 5
2013/10/01 apple 1
2013/10/01 pear 2
2013/10/02 apple 5
Run Code Online (Sandbox Code Playgroud)
我想要的只是显示每个月每个水果的总和,输出将是这样的:
date no_of_apple no_of_pear
2013/09 10 5
2013/10 6 2
Run Code Online (Sandbox Code Playgroud)
我试图像这样构建 linq 但被卡住了:
from o in fruit
let keys = new
{
date = o.date.ToString("yyyy/MM"),
fruit = o.fruit_code
}
group o by keys into grp
select new
{
date = grp.Key.date,
no_of_apple = // I got stucked here, wondering how to
no_of_pear = // calculate the conditional sum
}
Run Code Online (Sandbox Code Playgroud)
先感谢您。