1,469 views
0 votes
0 votes

Write a SQL Query for : Find those ratings for which the average age of sailors is the minimum over all ratings.

Query 1: 

SELECT Temp.rating, Temp.avgage 

FROM (SELECT S.rating, AVG(S.age) AS avgage,

             FROM Sailors S

             GROUP BY S.rating) AS Temp

WHERE Temp.avgage = (SELECT MIN(Temp.avgage) FROM Temp)

Query 2 :

SELECT Temp.rating, MIN(Temp.avgage)

FROM (SELECT S.rating, AVG(S.age) AS avgage,

             FROM Sailors S

             GROUP BY S.rating) as Temp

GROUP BY Temp.rating

Are Query 1 and Query 2 equivalent ? Do comment.

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
3
rayhanrjt asked Jan 6, 2023
787 views
Write SQL command to find DepartmentID, EmployeeName from Employee table whose average salary is above 20000.
2 votes
2 votes
1 answer
4
Subhrangsu asked Jun 18, 2022
450 views
Write SQL query to show all employees hired on June 4,1984 (non-default format)emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)