0

I am trying to do exactly what the title says, get the total number of records and the number of records that are unique in a certain column.

What I tried so far

SELECT COUNT(ip) AS visits, ip FROM tracker WHERE time BETWEEN ? AND ? GROUP BY ip

SELECT DISTINCT COUNT(ip) AS visits, ip FROM tracker WHERE time BETWEEN ? AND ?

SELECT DCOUNT(ip) AS visits, DISTINCT(ip) AS `unique` FROM tracker WHERE time BETWEEN ? AND ?

However none of these brought me pleasant feelings.. How can I do this?

1 Answer 1

1

I believe that what you need is this

SELECT COUNT(DISTINCT)

So it should be :

SELECT COUNT(DISTINCT ip) AS visits FROM tracker;
Sign up to request clarification or add additional context in comments.

2 Comments

Now I'm left to wonder if this is efficient or not :D. Thanks!
I have to say that I'm wondering the same. But I've to add that a where statement will help you to increase the performance if we talk about a specific period of time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.