I am trying to convert following MySQL query to Hive
MySQL Query
SELECT
departments.dept_name,
dept_emp.dept_no,
gender,
(count(*)/(select count(*) from employees)) AS Sex
FROM
employees,
dept_emp,departments
WHERE
dept_emp.dept_no = departments.dept_no
AND dept_emp.emp_no = employees.emp_no
GROUP BY
dept_emp.dept_no,
departments.dept_name,
gender
ORDER BY
dept_emp.dept_no;
Hive Query
WITH
q1 as (SELECT COUNT(*) AS TOTAL_COUNT FROM employees),
q2 as (SELECT gender,COUNT(*) as gender_count FROM employees GROUP BY gender)
SELECT
departments.dept_name,
dept_emp.dept_no,
gender,
gender_count/TOTAL_COUNT As Sex
FROM
q1,
q2,
dept_emp,
departments
WHERE
dept_emp.dept_no = departments.dept_no
AND dept_emp.emp_no = dept_emp.emp_no
GROUP BY
dept_emp.dept_no,
departments.dept_name,
q2.gender
ORDER BY
dept_emp.dept_no;
But I am getting error
SemanticException [Error 10025]: Line 3:53 Expression not in
GROUP BY
key :TOTAL_COUNT
Thank you in Advance!