Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Update Employee Sex Codes in SQL

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

Your question is Update Employee Sex Codes in SQL. 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

I need to update a table where '1' and '0' were incorrectly assigned for employee sex; how can I change '1' to represent females and '0' to represent males? Write a PostgreSQL statement that updates only these two codes and leaves NULL or other values unchanged.

Output

  1. Return one row per updated employee with employee_id and the corrected sex.
  2. Sort rows by employee_id ascending.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee name
sexVARCHAR(20)Employee sex value, including incorrectly coded and corrected values
departmentVARCHAR(50)Employee department
Tablesemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results