To find out if a customer has visited more than once in a day you could do:
SELECT customer_id, count(*) as numberOfVisits
FROM gym_visits
WHERE checkin_time = <some date value>
GROUP BY customer_id
To find out possible friends of customers who came into the gym within a certain time interval without looping through the table per customer requires a different strategy. One way to do it would be as follows:
CREATE TABLE friends
(
customer_id int,
friend_id int
// add other columns as you see fit
)
Create another table with the above structure:
Create an insert trigger on the gym_visits table. When a new customer arrives at time NOW(), the trigger will find all the customers in the gym_visits table who have arrived between NOW() - X minutes (X being any interval/rolling time window you choose). This trigger will then insert a row for all customers it has found in that interval (ie possible friends) into the friends table for that new customer. This way you easily capture possible friendships and the table contains all the details to allow you to produce a social graph of possible friendships.