The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Doubt in one query

Doubt in one query

0
Votes
2
Answer

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

365 Team
0
Votes

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

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

6 months

365 Team
0
Votes

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

×
Ready to Learn
Data Science?
50% OFF