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.
What is the basic difference between Gross NPA and Net NPA?
I- Gross NPA is the total of Bank loans and Net NPA is the total of all kinds of loan...
Which of the following statements about Prompt Corrective Action is/are True?
I-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Prompt Corrective Action F...
Who among the following is not one of the eligible beneficiaries of PMUY?
Which of the following Statements about IREDA is/are True?
I- It is registered as Non-Banking Financial Company (NFBC) with Reserve Bank of India...
Which of the following Statements about Multiplier Effect is/are True?
I- When the government spends a rupee, overall income rises by a multiple ...
When Government expenditure is more than income, through which of the following ways, it does the deficit financing?
(1) From Banks
(2) Fr...
Consider the following statements regarding Phase II of the Swachh Bharat Mission (Grameen) [SBM (G)]
1) The program will be implemented...