select grade, (case when exists(select 1 from tab1 where grade = a.grade and score <> 'A') then 0 else 1 end) as gscore into tab2 from tab1 a group by grade
select grade,case when exists(select 1 from tab1 where grade=a.grade and score<>'A') then 0 else 1 end gscore into tab2 from tab1 a group by gradeok
(case when exists(select 1 from tab1 where grade = a.grade and score <> 'A') then 0 else 1 end) as gscore
into tab2 from tab1 a
group by grade