There is a table with objects:

CREATE TABLE public.predm ( -- Полное название предмета maxname text COLLATE pg_catalog."default" NOT NULL, -- Короткое название предмета minname text COLLATE pg_catalog."default", -- Шифр предмета shifr text COLLATE pg_catalog."default", -- Год учебной программы gpr_go integer NOT NULL, -- Семестр sem_per integer NOT NULL, -- Категория (Курсовой проект, зачет без оценки, зачет с оценкой, экзамен) kateg integer NOT NULL, -- Специальность spec integer NOT NULL, CONSTRAINT predm_pkey PRIMARY KEY (maxname, gpr_go, sem_per, kateg) ) 

Pupils grades table:

 CREATE TABLE public.ocenki ( predm text COLLATE pg_catalog."default" NOT NULL, gg integer NOT NULL, sp integer NOT NULL, -- Оценка oc integer NOT NULL, -- ID учащегося id integer NOT NULL, kateg integer NOT NULL, CONSTRAINT oc_pc PRIMARY KEY (kateg, predm, gg, sp, id) ) 

It is necessary to first look for the maximum category (KP, ZBO, ZSO, Ex) for a specific subject (it turns out a table with columns: Subject, Category) and add to the structure

 select maxname, max(predm.kateg) from public.ocenki, predm where ocenki.predm = minname and predm.kateg=ocenki.kateg and id = " + ln_list[comboBox5.SelectedIndex] + @" and sem_per = sp group by maxname 

Then I collect the request for a piece:

  если(к_во_предметов > 0) { q="(запрос для первого предмета в списке)"; for(int i = 0 ; i < к-во_предметов; i++) q+="union (запрос для i-того предмета в списке); } 

Are there any easier ways to get what you need?

  • Specify for the beginning the statement of the problem, what exactly should go to the result. In my diploma supplement, course projects are completely separate entries. test or exam plus a separate mark for the course in the same subject. That is, for the university I completed, your algorithm is wrong. - Shallow
  • What red should get. Kursach a separate request. i.stack.imgur.com/pyCk8.gif - Alexander Osipov
  • Those. if exams and tests were passed on the subject, then we display the last exam. If there were only offsets, then the last offset. - Alexander Osipov

0