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.
The Sampoornata Abhiyan, a campaign launched by NITI Aayog, aims to:
The DuPont Analysis uses the following ratios except:
What is the focus of the collaboration between IIT Madras and GIC Re in February 2023?
The income from the transfer of digital assets shall be taxed at ______?
The process of spreading investments across different assets or securities to reduce risk is called:
Capital structure of a firm influences the:
What is the minimum margin requirement for banks on equity shares / convertible debentures held in dematerialized form?
What is the maximum exposure limit to an individual borrower for Urban Co-operative Banks (UCBs) with deposits up to ₹10 Crore?
When employees exhibit control and restraint over himself/herself in difficult or adverse situations, it depicts which of the following characteristics?
Calls in arrear is shown in Balance Sheet as?