-- 只读基线：各模块目标空缺与最新日。不得修改业务数据。
SELECT module_code, COUNT(*) AS row_count, MAX(biz_date) AS max_biz_date,
       SUM(CASE WHEN target_value IS NULL THEN 1 ELSE 0 END) AS missing_target
FROM ado_s9_kpi_value_l1_day
WHERE is_deleted = 0
GROUP BY module_code
ORDER BY module_code;

SELECT module_code, COUNT(*) AS missing_on_latest
FROM ado_s9_kpi_value_l1_day a
WHERE a.is_deleted = 0
  AND a.target_value IS NULL
  AND a.biz_date = (SELECT MAX(b.biz_date) FROM ado_s9_kpi_value_l1_day b WHERE b.module_code = a.module_code AND b.is_deleted = 0)
GROUP BY module_code;

SELECT source_type, COUNT(*) AS cnt
FROM mdp_source
GROUP BY source_type;
