SQL using a function to check existence of event over a user id

welcome to shbcf.ru