let newest_employees = (
from employees
sort tenure
take 50
)
let 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]
WITH newest_employees AS (
SELECT
*
FROM
employees
ORDER BY
tenure
LIMIT
50
), average_salaries AS (
SELECT
country,
AVG(salary) AS average_country_salary
FROM
salaries
GROUP BY
country
)
SELECT
newest_employees.name,
newest_employees.salary,
average_salaries.average_country_salary
FROM
newest_employees
JOIN average_salaries ON newest_employees.country = average_salaries.country