I am trying to make a stored procedure that, by introducing two parameters (numbers and letters of a class) into it, will give us the number of students in a class. failing and count. have time.
Here, the class number, letter and count. my pupils are good at everything, but there is a problem at stake. failing and count. have time. I can not understand how to ask them. For a very long time I tried to insert type conditions in where (mark <60 or mark> = 60). However, he could not combine it for the successful and not for the successful. Tell me how it can be done at all ...

CREATE or replace FUNCTION public.сlass3(dname varchar,dname1 varchar) RETURNS TABLE(numberr varchar(50), letterr varchar(50), kol int, kol_ne bigint, kol_ot bigint) security definer LANGUAGE plpgsql AS $$ BEGIN RETURN QUERY select c.number, c.letter, c.kol_ychenuk, count(o.id_pupil), count(o.id_pupil) from mark o,class c,pupil p where c.number =dname and c.letter =dname1 and mark <=60 and p.id_pupil = o.id_pupil and c.id_class = p.class group by c.number,c.letter,c.kol_ychenuk; END; $$; 
  • Please insert into the question the structure of your mark , pupil and class tables in the form of create table expressions - Sergey Nudnov
  • SUM(CASE WHEN mark<60 THEN 1 ELSE 0 END) AS count_losers and a similar expression for successors. - Akina

0