PRQL

table newest_employees = (
  from employees
  sort tenure
  take 50
)

table average_salaries = (
  from salaries
  group country (
    aggregate average_country_salary = (average salary)
  )
)

from newest_employees
join average_salaries [country]
select [name, salary, average_country_salary]

SQL

WITH newest_employees AS (
  SELECT
    employees.*
  FROM
    employees
  ORDER BY
    tenure
  LIMIT
    50
), average_salaries AS (
  SELECT
    country,
    AVG(salary) AS average_country_salary
  FROM
    salaries
  GROUP BY
    country
)
SELECT
  name,
  average_salaries.salary,
  average_salaries.average_country_salary
FROM
  newest_employees
  JOIN average_salaries USING(country)