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 does 'A' in ANSI stand for ____________.
Solve the quadratic equations and determine the relation between x and y:
Equation 1: 2x² - 10x + 12 = 0
Equation 2: 4y² - 16y + 15 = 0
315 people went to a park. The number of men is 25 more than the number of women and the number of adults is 15 more than the number of children. How ma...
A person borrows ₹5000 at 12% per annum simple interest. He repays ₹3200 at the end of 2 years. How much does he still owe after 2 years?
In a right triangle, the hypotenuse is 13 cm and one leg is 5 cm. What is the radius of the circle inscribed in the triangle?Â
If 15 men can complete a work in 24 days, how many days will it take 10 men to complete the same work?
A ladder leaning against a wall makes an angle of 60° with the ground. If the ladder is 10 meters long, how high up the wall does it reach?
A trader buys 400 shares of a company at Rs. 80 each, paying 1% brokerage on the purchase value. The company declares a dividend of 12% on the face valu...
The profit earned by selling a shirt for ₹500 is equal to the loss incurred by selling it for ₹400. Find the cost price of the shirt.