Скрипт для поиска КОСГУ, которые имеют более одной строки.
SELECT h . code AS KOSGU , k . description , k . begin_date , k . end_date , b . caption FROM KES_LINES k JOIN KES h ON h . id = k . master_id JOIN budget b ON b . id = k . budget_id WHERE k . master_id IN ( SELECT l . master_id FROM KES_LINES l GROUP BY l . master_id HAVING COUNT ( * ) > 1 ) ORDER BY h . code ;