The SQL statement 1 is something provided by the program you are testing and it is compared to the expected result, which is in the SQL statement 2. The sub compares both and returns a true result if both statements are equivalent (not necessarily exactly the same). This allows you to change the program generated SQL statement without having to change the test. As long as they parse to the same tree (and hence should be functionally equivalent) the program passes the test.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James