I wanted to print the highest average salary of a employees rounding the value upto 2 decimals places. How should i do it. It contains both max,avg. I am always getting an error.
Thanks for reaching out!
Can you please let us know the exact code you executed before obtaining this error? Also, can you please tell us what error message do you obtain exactly?
Also, can you please point which lecture does your question refer to?
Looking forward to your answer.
select student_id, round(max(value),2) as avg_mark from mark
where value=(select avg(value) from mark) group by student_id;. It is of type scaler and aggregate function. Learning it from udemy
Thanks for providing the code.
We don’t have a table called ‘mark’ in our database. But I presume you are referring to the salary field from the salaries table, right? And your student_id is actually the emp_no field, is that correct?
If this is indeed the case, then you have to clarify what do you exactly want to retrieve from the dataset.
By definition, if you obtain an average value, it’s not a maximum value.
However, you may have actually wanted to extract all average salaries (just as they have been provided in the salaries table) and then retrieve the highest, say, 10 of them. Is this the case?
If yes, the following query may be the solution.
emp_no, ROUND(AVG(salary), 2) AS average_salary
GROUP BY emp_no
ORDER BY average_salary DESC
Hope this helps.