FNZ interview question

To optimize an obviously bad SQL query, to code a simple class in C#