Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Email Null Handling

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

Your question is SQL Email Null Handling. 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

Alcon is reviewing the completeness of contact records used for customer communications. Given the t1 table, write a PostgreSQL query that calculates what percentage of records contain an email address.

Treat an email address as present when email is non-null. The result should be safe against division by zero and should report the percentage rounded to two decimal places.

Requirements

  1. Return the total number of records and the number of records with non-null email addresses.
  2. Calculate the email coverage percentage as records_with_email / total_records * 100.
  3. Round the percentage to two decimal places and avoid integer division or division-by-zero errors.

Schema

t1
ColumnTypeDescription
nameVARCHAR(100)Alcon contact name
emailVARCHAR(255)Contact email address
Tablest1
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results