Knowee
Questions
Features
Study Tools

SELECT designation,avg(sales) from emp group by designation having avg(sales)>(SELECT avg(sales) from emp); explain it's working

Question

SELECT designation,avg(sales) from emp group by designation having avg(sales)>(SELECT avg(sales) from emp); explain it's working

🧐 Not the exact question you are looking for?Go ask a question

Solution

This SQL query is used to find the average sales of each designation in the 'emp' table where the average sales is greater than the overall average sales of all designations.

Here's how it works:

  1. SELECT designation, avg(sales) from emp group by designation: This part of the query is selecting the 'designation' and the average 'sales' from the 'emp' table. The 'group by' clause is used to arrange identical data into groups with the help of some functions. So here, it groups the data by 'designation'.

  2. having avg(sales)>(SELECT avg(sales) from emp): The 'having' clause is used because you want to filter the results of your aggregation. In this case, you only want the designations where the average sales are greater than the overall average sales. The overall average sales is found by the subquery (SELECT avg(sales) from emp), which calculates the average sales of all records in the 'emp' table.

So, in summary, this query is finding the designations where the average sales are greater than the overall average sales.

This problem has been solved

Similar Questions

Select the correct answerWhat will be the result of the following query? SELECT customer_id, AVG(total_amount) AS avg_amount FROM Orders GROUP BY customer_id HAVING AVG(total_amount) > 200;OptionsReturns the customer IDs and average order amounts for all customers.Returns the customer IDs and total order amounts for customers with an average order amount greater than 200.Returns an error because the HAVING clause is not allowed in this context.Returns the customer IDs and average order amounts for customers with an average order amount greater than 200.

Consider the following table Employee.Select the output returned by the following query: SELECT branch AS department, AVG(age) AS average_ageFROM employeeGROUP BY branchHAVING COUNT(*) >= 2ORDER BY average_age DESC;

29. What is the result of the following SQL Query? SELECT COUNT(*), AVG(amount) FROM Orders WHERE amount > 200; Number of orders with amount > 200 and the average amount of these orders.Total number of orders and the average amount of all orders.Number of customers with orders > 200 and the average order amount per customer.Total number of orders > 200 and the average number of orders.

Select the suitable option for displaying the average commission percentage of all employees, where the commission percentage column of certain employees include NULL value.Select one:a.select AVG(NVL(commission_pct)) from emp;b.select AVG(NVL(commission_pct,0)) from emp;c.select AVG(NVL(0,commission_pct)) from emp;d.select AVG(ommission_pct) from emp;

Raj, a Database Administrator, needs to display the average pay of workersfrom those departments which have more than five employees. He isexperiencing a problem while running the following query:SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5GROUP BY DEPT;Which of the following is a correct query to perform the given task?i. SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5GROUP BY DEPT;ii. SELECT DEPT, AVG(SAL) FROM EMP HAVING COUNT(*) >5 GROUP BY DEPT;iii. SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPTWHERE COUNT(*) > 5;iv. SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPTHAVING COUNT(*) > 5;

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.