-- This is part 1 of 2 of a query to get a list of exposures on which magic may be performed
-- After this follows magictool_definebyquery_select_part2.sql
SELECT
    exp_id,
    filter,
    num_todo,
    num_done
FROM (
    -- Number of skycells as a function of exposure
    SELECT
        exp_id,
        filter,
        COUNT(DISTINCT skycell_id) AS num_todo
    FROM rawExp
    JOIN chipRun USING(exp_id)
    JOIN camRun USING(chip_id)
    JOIN fakeRun USING(cam_id)
    JOIN warpRun USING(fake_id)
    JOIN warpSkyCellMap USING(warp_id)
    JOIN warpSkyfile USING(warp_id, skycell_id)
    WHERE
        warpSkyfile.ignored = 0
    AND warpRun.state = 'full'
-- INSERT HERE any additional restrictions (e.g., exp_id, warpSkyfile.good_frac)
-- INSERT HERE magictool_definebyquery_select_part2.sql
