PRQL

  1. let newest_employees = (
  2. from employees
  3. sort tenure
  4. take 50
  5. )
  6. let average_salaries = (
  7. from salaries
  8. group country (
  9. aggregate average_country_salary = (average salary)
  10. )
  11. )
  12. from newest_employees
  13. join average_salaries [==country]
  14. select [name, salary, average_country_salary]

SQL

  1. WITH newest_employees AS (
  2. SELECT
  3. *
  4. FROM
  5. employees
  6. ORDER BY
  7. tenure
  8. LIMIT
  9. 50
  10. ), average_salaries AS (
  11. SELECT
  12. country,
  13. AVG(salary) AS average_country_salary
  14. FROM
  15. salaries
  16. GROUP BY
  17. country
  18. )
  19. SELECT
  20. newest_employees.name,
  21. newest_employees.salary,
  22. average_salaries.average_country_salary
  23. FROM
  24. newest_employees
  25. JOIN average_salaries ON newest_employees.country = average_salaries.country