Changes between Version 7 and Version 8 of DatabaseProgramming-AdvDb


Ignore:
Timestamp:
06/08/26 08:46:51 (8 days ago)
Author:
231175
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DatabaseProgramming-AdvDb

    v7 v8  
    7777                       then ((v_earned_points::numeric / v_total_points) * 100)::int
    7878                   else 0 end;
    79    
     79
    8080    v_passed := v_score >= v_passing_score;
    8181
     
    8989
    9090    insert into quiz_attempt_answer (correct, quiz_question_id, quiz_attempt_id)
    91     select qao.correct,
    92            (a ->> 'question_id')::bigint,
    93            v_attempt_id
     91    select
     92        -- all correct options were selected AND no incorrect options were selected
     93        (count(*) filter (where qao.correct = true) =
     94         (select count(*)
     95          from quiz_answer_option
     96          where quiz_question_id = (a ->> 'question_id')::bigint
     97            and correct = true))
     98            and
     99        (count(*) filter (where qao.correct = false) = 0),
     100        (a ->> 'question_id')::bigint,
     101        v_attempt_id
    94102    from jsonb_array_elements(p_answers) a
    95              join quiz_answer_option qao on qao.id = (a ->> 'answer_option_id')::bigint;
     103             join quiz_answer_option qao on qao.id = (a ->> 'answer_option_id')::bigint
     104    group by (a ->> 'question_id');
    96105
    97106    insert into quiz_attempt_answer_selected_options (quiz_attempt_answer_id, quiz_answer_option_id)