D
D
DrunkMaster2016-04-17 07:36:42
SQL
DrunkMaster, 2016-04-17 07:36:42

How to select repetitions by SQL query?

Table with data of site visitors. You need to find out if there are ips that are repeated every day, for example 100.100.100.15
6a52b57e94a14cf68ba02241b0737414.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mletov, 2016-04-17
@DrunkMaster

SELECT ip
FROM
(
     SELECT ip, date
     FROM table 
     GROUP BY ip, date
) AS t1
GROUP BY ip
HAVING COUNT(ip) = (SELECT COUNT(date)  FROM table GROUP BY date)

This is a request to select an ip that occurs every day. Or are you interested in ip that are repeated at least once?
Then:
SELECT ip
FROM
(
     SELECT ip, date
     FROM table 
     GROUP BY ip, date
) AS t1
GROUP BY ip
HAVING COUNT(ip) > 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question