请问如何将Query对象和表关联查询? 返回

SqlSugar 老数据
3 2565

具体SQL如下:

Select c.ID,c.Name,d.ID,d.Name,a.Days,OrderCount=Count(b.ID),MinOrderTime=Min(b.CreateTime),OrderMoney=Sum(b.Receivables) From (

Select ID=Max(ID),Client,Days=Max(Days) From Order_Main 

Where Days >= 90 And Shop = 1 And Valid = 1 And PlatForm = 1

Group By Client

) a

Left Join Order_Main b On a.Client = b.Client And b.ID >= a.ID And b.Valid = 1

Left Join Client_Info c On c.ID = a.Client

Left Join Basics_ShopInfo d On d.ID = b.Shop

Where c.Valid = 1 And d.Valid = 1

Group By c.ID,c.Name,d.ID,d.Name,a.Days


热忱回答3

  • Sum(b.Receivables) From (

    Select ID=Max(ID),Client,Days=Max(Days) From Order_Main 

    Where Days >= 90 And Shop = 1 And Valid = 1 And PlatForm = 1

    Group By Client

    ) a

    这句话跟本就不通

    0 回复
  • 看懂了格式化了一下

    0 回复
  • 分成2次查询然后JOIN   

     var list = db.Queryable<Order_Main, Client_Info>((st,sc)=>new object[] {

                    ...

                }).Select((st, sc) => new () {... });


                var groupList = db.Queryable<Order_Main>().Where(a=>a.Days>=90).GroupBy(a=>a.Client).Select(xx);


     

                var leftJoinList = db.Queryable(list, groupList, JoinType.Left, (j1, j2) => j1.Client == j2.Client).Select((j1, j2) => new { xxx}).ToList(); 


    0 回复