Hey,
I'm working on a simple project to create tables and insert data into them, and finally execute some queries. Please note: I'm using MySQL command client.
My schema is easy to implement; it's no problem.
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pct_time: integer)
Dept(did: integer, budget: real, managerid: integer)
My first question:
- Find the department with the highest average age of employees.
When I first read the question, it seems easy. However while implementing I can't get the results. I have many queries like this, can someone explain the steps to make these queries easier?
I use the following query to get the avg ages of the all employees. The next step is to get the MAX age, but how?
> SELECT AVG(E.age) FROM DEPT D,EMP E,WORKS W
> WHERE D.did=W.did and
> W.eid=E.eid GROUP BY D.did
If you know any good books for just understanding these types of queries, that will be fine for me.
Second question:
Sometimes some instructors or database managers want the relational algebra of the queries?
Knowing the relational algebra of the queries, why important?
And can we all implement all these complex queries by using relational algebra?