3
I have the following exercise:
- List the department code and name, newest and oldest admission date of each department, sort by department name.
Here’s what I did:
select d.department_id, d.department_name, max(jh.start_date), min(jh.start_date) from departments d
inner join job_history jh on jh.department_id = d.department_id
group by d.department_id order by d.department_name;
But give the error below, I like to know why it happens and how to solve.
ORA-00979: não é uma expressão GROUP BY 00979. 00000 - "not a GROUP BY expression" *Cause: *Action: Erro na linha: 45 Coluna: 25
What’s your question? Providing only the statement doesn’t help much, edit the question and provide more details than you’re having trouble with.
– user28595
That’s the problem, I made the answer based on the statement I put described. But since I’m a beginner I don’t know why group by is giving error. After some research I discovered that the resolution would be by group by but I do not understand the error...
– A. Fernando
Try grouping by all the fields you put in select, at least it’s how most banks work.
– rray
Gave the following error:ORA-00934: group function is not allowed here 00934. 00000 - "group Function is not allowed here" *Cause: *Action: Line error: 47 Column: 46
– A. Fernando
Try to play your database on this site so we can try to help you: http:/sqlfiddle.com/
– Laércio Lopes
Try it this way:
select d.department_id, d.department_name, max(jh.start_date), min(jh.start_date) from departments d
inner join job_history jh on jh.department_id = d.department_id
group by d.department_id order by d.department_id, d.department_name;
– R.Santos
My BD is one that oracle provides for download and testing, the Diagram of it is available in image
– A. Fernando
@R.Santos gave the same friend error...
– A. Fernando