cswork / libraryOpen practice workspace

Coding questions · Amazon

Consolidate and Rank Global Salaries in USD

This question evaluates data consolidation, currency normalization, and ranking competencies, measuring the ability to combine country-specific employee data and convert salaries into a common USD basis within the Data Manipulation (SQL/Python) domain.

employees_us

+---------+----------+--------+---------+
| emp_id  | name     | salary | country |
+---------+----------+--------+---------+
| 1       | Alice    | 120000 | US      |
| 2       | Bob      | 95000  | US      |
| 3       | Carol    | 115000 | US      |

exchange_rates

+----------+----------+
| currency | usd_rate |
+----------+----------+
| USD      | 1.0      |
| EUR      | 1.12     |
| JPY      | 0.0091   |
Scenario

Global HR reporting: consolidate country files and rank worldwide salaries.

Question

Append several country-specific employee tables into a single global table. Using an exchange-rate reference table, find the top 10 salaries worldwide in USD.

Hints

Show UNION-ALL, JOIN with exchange rates, order by converted salary, and limit 10.

Global top salaries in USD using UNION and exchange rates

You are given country-specific employee tables and a reference table of currency exchange rates to USD. For this example, only the US employee table is shown (employees_us), but assume similar tables exist for other countries. Append all country-specific employee tables into a single global dataset. Then, by joining to the exchange_rates table and converting all salaries to USD, return the top 10 employees worldwide ordered by salary in USD (highest first). Include employee ID, name, country, currency, and the converted salary in USD.

Table employees_us

columntypeconstraints
emp_idINTEGERPRIMARY KEY, NOT NULL
nameVARCHAR(100)NOT NULL
salaryINTEGERNOT NULL
countryVARCHAR(2)NOT NULL

Sample data:

countryemp_idnamesalary
US1Alice120000
US2Bob95000
US3Carol115000

Table exchange_rates

columntypeconstraints
currencyVARCHAR(3)PRIMARY KEY, NOT NULL
usd_rateDECIMAL(12,6)NOT NULL

Sample data:

currencyusd_rate
USD1
EUR1.12
JPY0.0091

Expected output

Top 10 employees worldwide by salary converted to USD, ordered from highest to lowest. With the provided sample data (only US employees, whose salaries are already in USD), the result includes the 3 US employees ordered by salary.

countrycurrencyemp_idnamesalary_usd
USUSD1Alice120000
USUSD3Carol115000
USUSD2Bob95000

Hints

  1. Use UNION ALL to append multiple country-specific employee tables into a single derived table (CTE or subquery).
  2. Include a currency column in the unified employee dataset so you can join to exchange_rates.
  3. Convert each salary to USD using salary * usd_rate.
  4. Order by the converted salary in descending order and return only the first 10 rows (e.g., using LIMIT 10 or an equivalent clause).