-- 查出导致「科技部老师开单业绩」多于「科美业绩」的那些开单数据（科技部表里 非科美 或 品项分类为空 的明细）
-- 时间范围：与台账一致 2026-01-01 ~ 2026-01-22（若需整月可改为 2026-01-31 23:59:59）
SET @start = '2026-01-01 00:00:00';
SET @end   = '2026-01-22 23:59:59';

-- 差异来源：lq_kd_kjbsyj 中 F_ItemCategory 非科美或为空的记录（按开单号列出）
SELECT
    kd.F_Id AS 开单ID,
    kd.kdbh AS 开单编号,
    kd.kdrq AS 开单日期,
    k.F_Id AS 科技部业绩明细ID,
    COALESCE(k.F_ItemCategory, '(空)') AS 品项分类_科技部,
    CAST(NULLIF(TRIM(k.kjblsyj), '') AS DECIMAL(18,2)) AS 科技部业绩金额,
    k.yjsj AS 业绩时间
FROM lq_kd_kjbsyj k
INNER JOIN lq_kd_kdjlb kd ON k.glkdbh = kd.F_Id AND kd.F_IsEffective = 1
WHERE k.F_IsEffective = 1
  AND k.yjsj >= @start
  AND k.yjsj <= @end
  AND (k.F_ItemCategory IS NULL OR k.F_ItemCategory = '' OR k.F_ItemCategory != '科美')
  AND k.kjblsyj IS NOT NULL
  AND TRIM(k.kjblsyj) != ''
  AND TRIM(k.kjblsyj) != '0'
ORDER BY kd.kdrq, kd.F_Id, k.yjsj;
