I have two table, defined by this create statement
CREATE TABLE PROJECT (project_name varchar(255), project_budget int, dedicated_project_leader int, dedicated_lead_developer int, dedicated_lead_consultant int, company_id int, project_id int, PRIMARY KEY (project_id));
CREATE TABLE WORKER (worker_name varchar(255), worker_salary int, worker_anual_bonus int, worker_type varchar(255), leader int, company_id int, project_id int, worker_id int, PRIMARY KEY (worker_id));
I'd like to ask for the sum of the budgets of the project than divide it by the number of the workers---)
SELECT (SUM(p.project_budget) / (SELECT count(WORKER.WORKER_NAME) from WORKER)) as AVG_BONUS
FROM PROJECT p;
Unfortunateley this raise an "ORA--00937:not a single-group group function" exception.
However if i execute this query:
SELECT count(WORKER.WORKER_NAME) from WORKER)
The result will be:
16
And if i divide the summa of budgets with the number instead of the result:
SELECT (SUM(p.project_budget) / 16) as AVG_BONUS
FROM PROJECT p;
I also got a perfect result e.g.:
294117,647058823
The solution is that i need to group by some id defined at the project table, but don't think it is logical....
SELECT (SUM(p.project_budget) / (SELECT count(WORKER.WORKER_NAME) from WORKER)) as AVG_BONUS
FROM PROJECT p
GROUP BY p.company_id;
It is also working.
Is anyone has a suggestion why can't i use it? (I have a feeling it is only an sql language specification that there can not exist two group function at a select without group by...)