--
-- Looking at the state-wide December 1st counts for a given year and grade
-- level, how many students were there for each primary disability type?
--

DROP FUNCTION IF EXISTS deccnt_state(sch_year integer, grade_num integer);

CREATE FUNCTION deccnt_state(sch_year integer, grade_num integer)
RETURNS TABLE(dis_type text, dec1_cnt integer) AS $$

  SELECT
    disabil_type,
    dec1_cnt
  FROM dec_child_count
  WHERE sch_year = $1
    AND grade_num = $2
    AND disabil_type != 'ALL'
    -- state level
    AND div_num = 0
    AND sch_num = 0
    -- all students
    AND race = 'ALL'
    AND gender = 'ALL'
    AND disabil = 'Y'
    AND lep = 'ALL'
    AND disadva = 'ALL'

$$ LANGUAGE SQL STABLE STRICT;

ALTER FUNCTION deccnt_state(sch_year integer, grade_num integer) OWNER TO absent;
