Posted by Yogita, Nov. 11, 2021, 9:59 a.m.
SQL Question 28
Thanks !
Posted by Yogita, Nov. 11, 2021, 9:59 a.m.
Great insight, thanks Mike.
In relation to this question, I got the same answer but through a different method. I used DENSE_RANK() OVER(ORDER BY COUNT(fa.actor_id) DESC)
Am I correct to think that as long as I can explain my logic in reaching the same solution, that I should be okay? Or will interviewers be concerned about query efficiency? (It doesn't show here, but on sites like Leetcode they measure your query speed)
Edit* I see you can check 'Query Analysis' to see the execution time. In this case, mine took 3.1ms while the official solution took 1.5ms. I also used a sub query instead of CTE, so that may have played a part. But question remains the same - is efficiency in query times an important factor to consider in interviews? Should I spend time to writing better queries even if the end result may be the same?
@Andrew - Forgive me for not being able to comment within the chain, but wanted to get you an answer regarding efficiency. I would mainly focus on correctness first, then worry about the performance later. This can be a little tricky as there are many sub-optimal ways to solve a query, but I don't think you need to spend an inordinate amount of time on getting the absolute best performance. If an interviewer asks you how you would improve performance, it helps to have a few ideas up your sleeve of how to do so (and remember that there are often trade-offs in performance.) You could also ask questions of the interviewer in this regard (how often are you running this query? Can you add indexes to assist? Can the data be denormalized in any way?, etc).
Hope this helps -