What is your most obscure piece of SQL knowledge?
I'm a bit peeved as I did a SQL test with an interviewer the other day, and the interviewer deliberately steered me away from the correct answer. It had to do with averages of salary for each manager, but 1 of the managers had no employees. You do a simple average on it, but it doesn't return an average for the manager with no employees.
I started to re-write the query to use COALESCE, which is correct, but the interviewer said that query is not returning nulls, so why would COALESCE help here.
I should have trusted myself and finished it that way, but deleted that new part and tried some other ways.
Lesson, trust your instincts, and COALESCE will let you return 0 if a category has no entries.