SELECT
s.studentid
, s.grade_level
, ac.hb
FROM students s
INNER JOIN (
SELECT
studentid
, MAX(CASE WHEN Att_Code IN ('HB') THEN 1 ELSE 0 END) AS hb
FROM Attendance_Code
GROUP BY
studentid
) ac ON s.studentid = ac.studentid
select count(case when "11" > 0 then 1 end) total_for_11,
count(case when "12" > 0 then 1 end) total_for_12
from (
select student_number,
count(case when att_code='HB' and grade_level='11' then 1 end) "11",
count(case when att_code='HB' and grade_level='12' then 1 end) "12"
from tab1
group by student_number
)
/
a guess : the count(*) counts over student , so wil count 2 when the students attents 2 times
to get 1 change every sum value other then 0 to 1
example
select U.TABLE_NAME, COLUMN_NAME
,CASE CASE WHEN column_name like 'C%' THEN count(*) over (partition by column_name) ELSE 0 end
WHEN 0 THEN 0
ELSE 1
END "CNT1"
,CASE WHEN column_name like 'C%' THEN count(*) over (partition by column_name) ELSE 0 end "CNT2"
from user_tab_columns U