-- Mart: KS2 performance fact table — one row per URN per year
-- Includes predecessor data via lineage resolution

select
    current_urn as urn,
    source_urn,
    year,
    total_pupils,
    eligible_pupils,

    -- Core attainment
    rwm_expected_pct,
    rwm_high_pct,
    reading_expected_pct,
    reading_high_pct,
    reading_avg_score,
    reading_progress,
    reading_progress_lower_ci,
    reading_progress_upper_ci,
    writing_expected_pct,
    writing_high_pct,
    writing_progress,
    writing_progress_lower_ci,
    writing_progress_upper_ci,
    writing_working_towards_pct,
    maths_expected_pct,
    maths_high_pct,
    maths_avg_score,
    maths_progress,
    maths_progress_lower_ci,
    maths_progress_upper_ci,
    gps_expected_pct,
    gps_high_pct,
    gps_avg_score,
    science_expected_pct,

    -- Absence
    reading_absence_pct,
    writing_absence_pct,
    maths_absence_pct,
    gps_absence_pct,
    science_absence_pct,

    -- Gender
    rwm_expected_boys_pct,
    rwm_high_boys_pct,
    rwm_expected_girls_pct,
    rwm_high_girls_pct,

    -- Disadvantaged
    rwm_expected_disadvantaged_pct,
    rwm_expected_non_disadvantaged_pct,
    disadvantaged_gap,

    -- Context
    disadvantaged_pct,
    eal_pct,
    sen_support_pct,
    sen_ehcp_pct,
    stability_pct

from {{ ref('int_ks2_with_lineage') }}
