FastPrepAverage Marks per Student and Subject
Problems/Average Marks per Student and Subject

Average Marks per Student and Subject

Bank of America logoBank of America● EasyNEW GRADONSITE INTERVIEW

Updated Dec 2020

QuestionConstraints

Problem statement

Source note: Reported by a Bank of America new grad from a 2020 campus drive, in the second live technical round after the video step, among the DBMS questions. The candidate got a table of students, each row with an ID, a name, a class, a subject reference and the marks, plus a table of subject names, and had to write SQL for each student's average marks in every subject.

The report gives no data, output layout or rules for missing marks. Here, one student row is one test mark, an ungraded mark (NULL) is not counted, a student with no graded mark in a subject is left out for it, and the average is rounded to two decimal places. All data is ours.

Our version is about 90% the same as the reported question.

A school records exam results in two tables. Each row of student is one mark: the student's student_id, name and class, the subject_id the mark belongs to, and the marks scored. A student who took several tests in a subject has several rows for it. The subject table gives the subject_name of each subject_id.

Write a query that finds every student's average mark in each subject they were graded in. Return student_id, name, subject_name and avg_marks, the average rounded to 2 decimal places.

A NULL in marks is a test that has not been graded yet and does not count toward the average. If a student has no graded mark at all in a subject, leave that student and subject out. Return the rows in any order.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

subject

One row per subject.

ColumnTypeNullableDescription
subject_idPKIntegerNoUnique subject ID.
subject_nameTextNoThe subject's name.

student

One row per mark: a student, a subject and the score on one test.

ColumnTypeNullableDescription
student_idIntegerNoThe student's ID; repeats on each of their rows.
nameTextNoThe student's name.
classTextNoThe student's class.
subject_idIntegerNoThe subject this mark is for.
marksIntegerYesScore from 0 to 100, or NULL if not graded yet.

Foreign key: subject_id → subject(subject_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
student_idIntegerNo—
nameTextNo—
subject_nameTextNo—
avg_marksDecimalNo—

Row order: any order is accepted. Numeric tolerance: 0.

Constraints

  • The subject table has between 1 and 50 rows, and subject_id is unique. The student table has between 0 and 1000 rows.
  • Every student.subject_id appears in subject.
  • marks is an integer from 0 to 100, or NULL. No other column is ever NULL.
  • All rows with the same student_id have the same name and class. Two different students can have the same name.
  • A student has at most 20 rows for one subject.
  • subject_name values are unique, and no two names in a column differ only in letter case.
  • No average lands exactly halfway between two hundredths, so any usual rounding gives the same result.

More Bank of America Onsite Interview questions

  • Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
  • Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
  • N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
  • Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
  • Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
  • Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
  • Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
  • Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
  • Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023

Similar questions at other companies

  • Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
  • Records Created or Updated in a Time WindowPelatro · ONSITE INTERVIEW
  • Top Ten Employee SalariesSolytics Partners · ONSITE INTERVIEW
  • Latest New JobSphere · ONSITE INTERVIEW
  • Employees Whose Manager Left the CompanyZS · ONSITE INTERVIEWZS interview questions
  • Employees Above Average SalaryJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Retrieve Every Student RecordLSEG · ONSITE INTERVIEWLSEG interview questions
  • Combine Winner and Loser NamesAmazon · ONSITE INTERVIEW
  • Conditionally Insert or Update RecordsKlaviyo · ONSITE INTERVIEWKlaviyo interview questions
  • Employees with Matching DepartmentsAMD · ONSITE INTERVIEWAMD interview questions

Bank of America interview experiences

  • Bank of America interviews · December 2025
  • Bank of America OA · December 2025
  • Bank of America interviews · September 2026
  • Bank of America OA · September 2026
All Bank of America interview questionsSee Bank of America hiring insights