Hello Im trying to import this query to toad but I got an error
Error:
"[Microsoft][ODBC Excel Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."
SQL QUERY:
WITH DepartmentSalaries AS (
SELECT
department_id,
AVG(salary) AS avg_salary
FROM
employees
GROUP BY
department_id
)
SELECT
e.employee_id,
e.employee_name,
ds.avg_salary
FROM
employees e
JOIN
DepartmentSalaries ds
ON
e.department_id = ds.department_id;
The issue you’re encountering with CTEs is likely due to the limitations of the ODBC Excel driver, which doesn’t support Common Table Expressions (CTEs). To make your query compatible with the Excel ODBC driver, try rewriting it using subqueries instead of a CTE. Here’s an example:
SELECT
e.employee_id,
e.employee_name,
ds.avg_salary
FROM
employees e
JOIN (
SELECT
department_id,
AVG(salary) AS avg_salary
FROM
employees
GROUP BY
department_id
) ds
ON
e.department_id = ds.department_id;