Added counting functionality to SQL