Last answered:

07 Apr 2020

Posted on:

05 Apr 2020

0

Doubt in one query

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.
2 answers ( 0 marked as helpful)
Instructor
Posted on:

07 Apr 2020

0
Hi Kshitij! 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? Thank you.
Looking forward to your answer.
Best,
Martin
Instructor
Posted on:

07 Apr 2020

0
Hi Kshitij! 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.
SELECT 
emp_no, ROUND(AVG(salary), 2) AS average_salary
FROM
salaries
GROUP BY emp_no
ORDER BY average_salary DESC
LIMIT 10;
Hope this helps.
Best,
Martin

Submit an answer