Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Weekly Error Codes

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Weekly Error Codes. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

NovaCare wants a quick view of which application errors are happening most often in recent customer logs. Write a SQL query to find the most common error_code values from the last 7 days.

Requirements

  1. Use only rows from the last 7 days based on log_time.
  2. Exclude rows where error_code is NULL.
  3. Return each error_code and its occurrence count as error_count.
  4. Sort by error_count descending, then error_code ascending.

Schema

customer_logs
ColumnTypeDescription
log_idPKINTPrimary key for each log entry
customer_idINTCustomer associated with the log
log_timeTIMESTAMPTimestamp when the log was recorded
log_levelVARCHAR(20)Severity level of the log event
error_codeVARCHAR(20)Application error code if present
messageTEXTRaw log message
Tablescustomer_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results