INNER JOIN rb_education_contract ec on g.Id = ec.GuestId
LEFT JOIN (SELECT ch.OrderGuestId, SUM(ch.CurrentDeductionHours) AS CurrentDeductionHours FROM rb_class_check ch WHERE `Status` =0 GROUP BY ch.OrderGuestId) cc on cc.OrderGuestId = g.Id
)q GROUP BY q.OrderId) ttt on ttt.OrderId = o.OrderId
WHERE o.Group_Id={group_Id} and o.OrderState <> 3 and o.EnterID >0 {where} and o.CreateTime >='{startMonth}' and o.CreateTime <='{endMonth}'
WHERE o.Group_Id={group_Id} and o.OrderState <> 3 and o.EnterID >0 {where} and o.CreateTime >='{startMonth}' and o.CreateTime <='{endMonth} 23:59:59'
GROUP BY o.EnterID ORDER BY SUM(o.Income + o.PlatformTax - o.Refund) DESC
+ec.FirstClassFee + ec.SecondClassFee + ec.ThirdClassFee as TotalSub
,ec.FirstClassHours + ec.SecondClassHours + ec.ThirdClassHours as ClassHours
,cc.CurrentDeductionHours
FROM rb_order_guest g
INNER JOIN rb_education_contract ec on g.Id = ec.GuestId
INNER JOIN (
SELECT ch.OrderGuestId, SUM(ch.CurrentDeductionHours) AS CurrentDeductionHours
FROM rb_class_check ch WHERE ch.`Status` =0 AND ch.ClassDate >='{startMonth}' AND ch.ClassDate <='{endMonth} 23:59:59' GROUP BY ch.OrderGuestId) cc on cc.OrderGuestId = g.Id
stringsql=$@"SELECT o.EnterID,COUNT(0) AS JKNum FROM rb_order_guest g
LEFT JOIN rb_order o on g.OrderId = o.OrderId
WHERE g.`Status`=0 and g.Group_Id ={group_Id} and g.GuestState =7 and o.OrderState <> 3 and g.GraduationTime >='{startMonth}' and g.GraduationTime >='{endMonth} 23:59:59'