0
0
PostgreSQLquery~10 mins

String aggregation with STRING_AGG in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to aggregate names into a single string separated by commas.

PostgreSQL
SELECT STRING_AGG(name, [1]) AS all_names FROM users;
Drag options to blanks, or click blank then click option'
A','
B' '
C';'
D'.'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semicolon ';' which is not a common separator in lists.
Forgetting to put the separator inside quotes.
Using a period '.' which is uncommon for separating names.
2fill in blank
medium

Complete the code to aggregate emails separated by a semicolon.

PostgreSQL
SELECT STRING_AGG(email, [1]) AS all_emails FROM contacts;
Drag options to blanks, or click blank then click option'
A'|'
B','
C':'
D';'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma ',' instead of a semicolon.
Not quoting the separator character.
Using a colon ':' which is not the requested separator.
3fill in blank
hard

Fix the error in the code to aggregate product names separated by a space.

PostgreSQL
SELECT STRING_AGG(product_name [1] ' ') AS products FROM inventory;
Drag options to blanks, or click blank then click option'
A;
B,
C(
D)
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the comma between arguments.
Using a semicolon instead of a comma.
Using parentheses incorrectly.
4fill in blank
hard

Fill both blanks to aggregate city names separated by a dash and order them alphabetically.

PostgreSQL
SELECT STRING_AGG(city, [1] ORDER BY [2]) AS cities FROM locations;
Drag options to blanks, or click blank then click option'
A'-'
Bcity
Cname
D'_'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an underscore '_' instead of a dash.
Ordering by a non-existent column like 'name'.
Forgetting to quote the separator.
5fill in blank
hard

Fill all three blanks to aggregate usernames in uppercase, separated by a colon, ordered by user ID.

PostgreSQL
SELECT STRING_AGG(UPPER([1]), [2] ORDER BY [3]) AS user_list FROM users;
Drag options to blanks, or click blank then click option'
Ausername
B':'
Cuser_id
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'username' or 'user_id'.
Forgetting to quote the separator.
Not using the correct column for ordering.