Select departments.department_name, COUNT(employees.department_id=departments.department_id) as "Count_employees"
FROM departments, employees
Where employees.department_id=departments.department_id
GROUP BY departments.department_name
UNION(
select 'Total' as department_name, Sum("Count_employees") as Count_employees
from departments, employees
)
Получаю ошибку:
ERROR: ОШИБКА: столбец "Count_employees" не существует
LINE 100: select 'Total' as department_name, Sum("Count_employees")...
^
HINT: Столбец "Count_employees" есть в таблице "*SELECT* 1", но на него нельзя ссылаться из этой части запроса.