SELECT CASE WHEN
    (SELECT COUNT(*) FROM `mdp_stg_so`
     WHERE `tenant_id` IN (0,1,1300000000001) OR (`tenant_id` > 0 AND `factory_id`=`tenant_id`))=0
AND (SELECT COUNT(*) FROM `mdp_std_so`
     WHERE `tenant_id` IN (0,1,1300000000001) OR (`tenant_id` > 0 AND `factory_id`=`tenant_id`))=0
AND (SELECT COUNT(*) FROM `dwd_ship_trans` WHERE `tenant_id` IN (0,1,1300000000001))=0
AND (SELECT COUNT(*) FROM `dwd_requirement_examine_detail` WHERE `tenant_id` IN (0,1,1300000000001))=0
AND (SELECT COUNT(*) FROM `ado_smart_ops_kpi_atomic_day` WHERE `tenant_id` IN (0,1,1300000000001))=0
AND (SELECT COUNT(*) FROM `mdp_sync_log` WHERE `tenant_id` IN (0,1,1300000000001))=0
AND (SELECT COUNT(*) FROM `mdp_transform_run_log` WHERE `tenant_id` IN (0,1,1300000000001))=0
AND (SELECT COUNT(*) FROM `ado_module_dashboard_rebuild_job`
     WHERE `status` IN ('QUEUED','RUNNING')
       AND (`tenant_id` IN (0,1,1300000000001) OR `factory_id`=`tenant_id`))=0
THEN 1 ELSE 0 END AS ok;
