Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Update Employee Sex Codes in SQL
00:00
5 left

Update Employee Sex Codes in SQL

EasySQL · PostgreSQL

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
Interviewer

Your question is Update Employee Sex Codes in SQL. Start with the requirements and the one table in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.