Advertisement
Maks140888

Untitled

May 27th, 2022
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.84 KB | None | 0 0
  1.  
  2. CREATE OR REPLACE FUNCTION min_grade_date (task_id number, student_id number)
  3. return varchar
  4. is
  5.     tutor_id number;
  6.     tutor_name varchar;
  7. begin
  8.     select g.tutor_id
  9.     into tutor_id
  10.     from grades g, user_web u, solution s, task t
  11.     where t.id = task_id
  12.     and u.id = student_id
  13.     and s.id = g.solution_id
  14.     and g.grade_date = (select min(grade_date) from grades g, user_web u, solution s, task t
  15.     where t.id = task_id
  16.     and u.id = student_id
  17.     and s.id = g.solution_id);
  18.    
  19.     select name into tutor_name from user_web where id =  tutor_id;      
  20.     return tutor_name;
  21.    
  22. end;
  23.  
  24.  
  25. select distinct s.student_id, t.title, min_grade_date(t.id, s.student_id)  
  26. from grades g, user_web u, solution s, task t
  27. where t.id = s.task_id
  28. and s.id = g.solution_id
  29. and u.id = g.tutor_id
  30. order by s.student_id
  31.  
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement