logo

Back to questions

Email Table Transformation

Medium

Each Facebook user can designate a personal email address, a business email address, and a recovery email address.

Unfortunately, the table is currently in the wrong format, so you need to transform its structure to show the following columns (see example output): user id, personal email, business email, and recovery email. Sort your answer by user id in ascending order.

Table:

Column NameType
user_idinteger
email_typevarchar
emailvarchar

Example Input:

user_idemail_typeemail
123personalhello@nicksingh.com
123businessnick@datalemur.com
123recoveryns2se@virginia.edu
234personalaubrey1986@gmail.com
234businessmgmt@ovo.com

Example Output:

Explanation

This task is basically just asking you to pivot/transform the shape of the data. It's all the same data as the input above, just in different format.

Each row will represent a single user with all three of their emails listed. The first row shows User ID 123 (who may or may not be Nick Singh); their personal email is hello@nicksingh.com, their business email is nick@datalemur.com, and so on.

PostgreSQL 14

Refer friends to get bonus content & cool prizes.