0
votes

I have a table students where I created column average_grades and I also have a table grades with columns G_id, g_grades, g_course, g_student, g_data.

I want to add all average grades to column in average_grades in students table have same errors my query is

insert into students (average_grades) 
    select avg(grades.g_grade) 
    from grades          

and my error

Error starting at line : 7 in command - insert into students (average_grades) select avg(grades.g_grade) from grades

Error report - SQL Error: ORA-01400: невозможно вставить NULL в ("DB_141ADM036"."STUDENTS"."ST_ID") 01400. 00000 - "cannot insert NULL into (%s)"
*Cause: An attempt was made to insert NULL into previously listed objects.
*Action: These objects cannot accept NULL values.

EDIT: translation from Russian:

ORA-01400: can not insert a NULL ("DB_141ADM036". "STUDENTS". "ST_ID")

1

1 Answers

0
votes

its seems you are inserting new record in student table and guess there is more column in student table that's value also need to be provide .

insert into students (S_id,average_grades) 
    select XXX, avg(grades.g_grade)  // logic to get student ID
    from grades  

I guess if you already inserted record in student table in that case you need to update average_grades column like

Update students 
SET average_grades = ( select avg(grades.g_grade  from grades ) 
WHERE Student_Id = XXX