AlgoMaster Logo

Exercise: Scalar Functions

Last Updated: May 10, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

rim whitespace and uppercase every artist name. Show artist_id, the original name, and the cleaned name aliased as cleaned. Order by artist_id.

SQL

Expected Query

Expected Output

Exercise 2

Easy

Round each payment's amount up to the next whole number using CEIL. Show payment_idamount, and the result aliased as rounded_up. Order by payment_id.

SQL

Expected Query

Expected Output

Exercise 3

Medium

Build a display label for each artist that combines the trimmed, uppercased name with the country in parentheses. Skip artists whose country is NULL. Show artist_id and the result aliased as label. Order by artist_id.

SQL

Expected Query

Expected Output

Exercise 4

Medium

Extract each user's email domain and count how many users share each domain. Show domain and the count aliased as user_count. Order by user_count descending, then domain ascending.

SQL

Expected Query

Expected Output

Exercise 5

Medium

Return only tracks whose track_id is even. Show track_idtitle, and duration_seconds. Order by track_id.

SQL

Expected Query

Expected Output

Exercise 6

Hard

Find payments where the amount differs from the refund amount, and return the absolute difference. Show payment_idamountrefund_amount, and the absolute difference aliased as diff. Order by diff descending, then payment_id ascending.

SQL

Expected Query

Expected Output