GroupBy分組的運用和linq左連線

2022-01-16 08:35:17 字數 2937 閱讀 4481

var conhistorylist = conhistorydata.groupby(g => g.personid);
就是conhistorydata是乙個iqueryable型別;

var conhistorylist = conhistorydata.groupby(g => g.personid).select(g => g.orderby(c => c.addtime));
對資料分組之後在根據每乙個分組內的某乙個元素排序。

var conhistorylist = conhistorydata.groupby(g => g.personid).select(g => g.orderby(c => c.addtime).firstordefault()).tolist();
對資料分組之後在根據每乙個分組內的某乙個元素排序。排序之後在返回第乙個元素,然後組成乙個集合返回。這個實現的是根據分組取組內第乙個元素然後重新返回乙個元素列表。

var dd = conhistorydata.groupby(g =>g.personid);

//獲取每個分組的鍵

foreach (var item indd)

}

var childdetaillistdata = new list();

var childdetaillistg = childdetaillist.groupby(b => b.materialcategory).select(g => g.groupby(b =>b.materialnum));

childdetaillist是乙個list集合。通過先分組materialcategory欄位,然後在在分組內根據materialnum欄位再次分組。

var childdetaillistdata = new list();

var childdetaillistg = childdetaillist.groupby(b => b.materialcategory).select(g => g.groupby(b =>b.materialnum));

foreach (var item inchilddetaillistg)}}

和上面使用元素差不多就是遍歷層數

var data = (from a in

childdata

join bj

inbjcostdata

on a.id equals bj.childid

into bj

from bje in

bj.defaultifempty()

join bjt

inbjrefunddata

on a.id equals bjt.childid

into bjt

from bjte in

bjt.defaultifempty()

//學平險

join xpx in

xpxcostdata

on a.id equals xpx.childid

into xpx

from xpxe in

xpx.defaultifempty()

join xpxt

inxpxrefunddata

on a.id equals xpxt.childid

into xpxt

from xpxte in

xpxt.defaultifempty()

//餐費

join cf in

cfcostdata

on a.id equals cf.childid

into cf

from cfe in

cf.defaultifempty()

join cft

incfrefunddata

on a.id equals cft.childid

into cft

from cfte in

cft.defaultifempty()

//自定義

join zdy in

zdycostdata

on a.id equals zdy.childid

into zdy

from zdye in

zdy.defaultifempty()

join zdyt

inzdyrefunddata

on a.id equals zdyt.childid

into zdyt

from zdyte in

zdyt.defaultifempty()

//休園

join xy in

xycostdata

on a.id equals xy.childid

into xy

from xye in

xy.defaultifempty()

join xyt

inxyrefunddata

on a.id equals xyt.childid

into xyt

from xyte in

xyt.defaultifempty()

//押金

join yj in

yjcostdata

on a.id equals yj.childid

into yj

from yje in

yj.defaultifempty()

join yjt

inyjrefunddata

on a.id equals yjt.childid

into yjt

from yjte in

yjt.defaultifempty()

select

newh_childstatistics

);

view code

python分組函式的使用 groupby

專案使用場景 需要對乙個包含字典的列表進行資料格式的轉化,指定 dict 中某個具體 key 的value 作為 新的 key,新的 value 是乙個列表,包含了原始的那些資料 from itertools import groupby from operator import itemgette...

Oracle的group by分組,子句增強

開篇還是想吐槽一下這個oracle的group by分組,沒有mysql那麼好用,可能是mysql用習慣了 create table employees employee id number 8 notnull 員工id manager id number 6 經理id salary number ...

Python中的分組函式groupby及其壓縮應用

我們先來看乙個題目 給定一組字元,使其壓縮,壓縮後的長度必須始終小於或等於原陣列長度。示例 1 輸入 a a b b c c c 輸出 a 2 b 2 c 3 說明 aa 被 a2 替代。bb 被 b2 替代。ccc 被 c3 替代。或者輸出乙個描述元組 輸入 a a b b c c c 輸出 a ...