SELECT
        (
         select co.name as padre
         from company co
         where  co.id = cc.parent_id
         ) as outsorce,
       c.name as empresa,
       #opp.name as Grupo_Nomina,
       count(distinct ppmc.condition_id) as colaboradores
FROM paysheet_paysheets ppsc
	INNER JOIN company c ON c.id = ppsc.company_id
  INNER JOIN os_payment_period opp ON  opp.company_id =  c.id and opp.id = ppsc.payment_period_id
	INNER JOIN paysheet_payments ppmc ON ppmc.paysheet_id = ppsc.id AND ppmc.`status` & 64 = 0  AND (ppsc.`status` & 32 > 0 OR ppsc.status & 4 >0)
  INNER JOIN user_condition uc ON uc.id = ppmc.condition_id
  LEFT JOIN company_company cc ON cc.child_id = c.id
  WHERE ppsc.company_id = c.id
  AND ppsc.second_day BETWEEN 'fecha-inicio 00:00:00' AND 'fecha-fin 23:59:59'
	AND ppsc.calculated_at is not null
  AND c.status = 2
  AND c.name NOT LIKE "%demo%" AND c.name NOT LIKE "%ejemplo%" AND c.name NOT LIKE "%winik%"
  AND c.name NOT LIKE "%alanach%" AND c.name NOT LIKE "%catchondo%" AND c.name NOT LIKE "%test%"
  AND c.name NOT LIKE "%abcdef%" AND c.name NOT LIKE "%onboarding%" AND c.name NOT LIKE "%jaime%"
  AND c.name NOT LIKE "%prueba%" AND c.name NOT LIKE "%demo%" AND c.name NOT LIKE "%mau%"  AND c.name != ""
  GROUP BY c.id
  ORDER BY outsorce ASC, empresa;