Question
Which SQL query will correctly calculate the average
salary of employees in each department and group them by department in a table named 'employees'?Solution
To calculate the average salary of employees in each department, we need to use the AVG() aggregate function in SQL. The GROUP BY clause is essential here, as it groups the results by department, ensuring the average is calculated for each individual department, not for the entire table. The correct SQL query is: SELECT department, AVG(salary) FROM employees GROUP BY department This query returns the department and the average salary of employees in that department. Why other options are wrong: b) SELECT department, SUM(salary) FROM employees GROUP BY department : This calculates the sum of the salary, not the average. It’s useful when you want the total salary for each department. c) SELECT department, AVG(salary) FROM employees : This query is incomplete because it lacks the GROUP BY clause. Without it, it would give the average salary for the entire table, not by department. d) SELECT AVG(salary) FROM employees GROUP BY department : This query incorrectly places the aggregate function without selecting the department column, which will result in an error or incorrect output. e) SELECT department, COUNT(salary) FROM employees GROUP BY department : This counts the number of salaries in each department, not the average salary.
Select the option in which the numbers are related in the same way as are the numbers of the following sets. Â
(11, 13, 72)
(19, 12, 93)<...
Select the option that is related to the third term in the same way as the second term is related to the first term.
AOE : FUJ :: RKT : ?
According to the logic used in the first pair, replace the question mark with the appropriate option given to
Cytology : Cells :: Entomology : ??
- If 834 = 96, 892 = 144, 765 = 210, then 953 = ?
- Select the option that is related to the third word in the same way as the second word is related to the first word.
Pencil : Stationery :: Spoon : ... Select the option that is related to the third term in the same way as the second term is related to the first term.
Pen ∶ Ink ∶∶ Fauce...
Select the combination of letters that when sequentially placed in the blanks of the given letter series will complete the series.
L L _ _ N O _ ...
Given set:[24, 16, 0]
Select the option that is related to the fifth letter-cluster in the same way as the second letter-cluster is related to the first letter-cluster and th...
Select the option that is related to the first number in the same way as the third number is related to fourth number and the fifth number is related to...