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

Stored procedures – Example – Part II

Stored procedures – Example – Part II

Super Learner
0
Votes
1
Answer

As the question was asking about finding the average salary, does this query work as well? I thought that we had to take into account the repeats in emp_no. 
SELECT
ROUND(AVG(salary), 2) AS average_salary
FROM
(SELECT
emp_no, salary, MAX(from_date), MAX(to_date)
FROM
salaries
GROUP BY emp_no
ORDER BY emp_no) AS A;
Also, I would like to understand more about the Error Code 1248: Every derived table must have its own alias. What’s the point of having the alias when I do not use it when executing it? Is there a more elegant way to type the code? Thanks in advance. 🙂 

1 Answer

365 Team
0
Votes

Hi Vivian!
Thanks for reaching out.

  1. This is a great observation. Yes, it does work. In our example, we wanted to focus on creating a MySQL Procedure, hence we have simplified that part of the answer.
  2. Providing the specific query you are referring to may help in our explanation. However, in general, the idea is that you need to provide aliases when using a subquery, since this is a selection of information that exists only temporarily. You can say that it exists only “in the life of the query”, so to speak. Therefore, it needs to be given an alias for a reference.   

Hope this helps.
Best,
Martin

Thank you 🙂

4 months

You are welcome! 🙂

4 months
×
LAST CHANCE
Ready to Learn Data Science?
50% OFF