/*
Amazon SQL Interview Question
You are given an Employee table with the following schema:
| Column | DataType | Description |
|----------|----------|------------------------------------------|
| id | INT | Unique identifier for each employee. |
| name | VARCHAR | Employee's name. |
| sex | CHAR | Gender: 'M' for Male, 'F' for Female. |
| salary | DECIMAL | Employee's salary. |
Write an SQL query to swap the gender values in the sex column
Return the updated table with all columns, but with the sex column modified accordingly.
The output should not modify the original table in the database.
*/
CREATE TABLE Employee (
id INT PRIMARY KEY,
name NVARCHAR(100) NOT NULL,
sex CHAR(1) CHECK (sex IN ('M', 'F')) NOT NULL,
salary DECIMAL(10, 2) NOT NULL
);
INSERT INTO Employee (id, name, sex, salary)
VALUES
(1, 'John Doe', 'M', 55000.50),
(2, 'Jane Smith', 'F', 62000.00),
(3, 'Robert Brown', 'M', 48000.75),
(4, 'Emily Davis', 'F', 75000.20),
(5, 'Michael Wilson', 'M', 58000.00),
(6, 'Sophia Johnson', 'F', 69000.90);
SELECT
id,
name,
CASE WHEN sex = 'M' THEN 'F' ELSE 'M' END AS sex,
salary
FROM Employee;
To embed this program on your website, copy the following code and paste it into your website's HTML: