Attempting to write meaninful SQL to decipher data