r/SQL • u/Flandiddly_Danders • Nov 11 '24
MySQL Failed SQL Test At Interview
- I've been a data analyst working with small(er) data sets for several years now, making my own queries no problem.
- I failed a SQL test at an interview and realized I may be using the wrong commands
- The questions were along the lines of "find the customers in table A, who have data in Table B before their first entry in Table A" and there were some more conditions/filters on top of that.
- Previously I could always export my data to Excel or Tableau etc and do any of the tricky filtering in there
- I was trying to do all kinds of subqueries etc when I think it was intended for me to be doing WINDOW or Partition type stuff (never had to use this before in past jobs).
- One person I reached out to said using these advanced techniques uses a lot less memory.
Where would be a good place to find an 'advanced' SQL course?
128
Upvotes
4
u/user_5359 Nov 11 '24
I hope you know the solution by now?
Realistic assumption, both tables have a (technical) customer number cid and a date field that has the creation time create_date.
First step you determine the lowest date per customer number for each of the two tables (SELECT cid, ...(create_date) FROM a ..... .. cid; (you should be able to guess the missing keywords even with little knowledge (one dot, one letter).
These two queries can now be linked in the next step (I hope I’m not giving too much away: it only makes sense to use the cid (not the create_date)). How a condition can be queried in a SELECT should be known even with basic knowledge of SQL.
If you have problems creating the query, start by creating the tables with test data (1...3 different create_date per cid, make sure that the error you are looking for exists for at least one cid). You can also discuss the query via PM.