If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Count Distinct (Per day) IP Addresses for a date range

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-12, 18:32
eagles396 eagles396 is offline
Registered User
 
Join Date: Dec 2006
Posts: 4
Count Distinct (Per day) IP Addresses for a date range

Hi,

I am looking for some help to create a mysql query to get the distinct (per day) count of ip addresses a link has been clicked for a date range.

Lets say my IP address clicks on the same link 5 times every day during January 2012 using the same ip address. There would be 155 (5*31) records in the table but the query result should display 31 as we are only counting the same ip address max of once per day.


Any help would be appreciated
Reply With Quote
  #2 (permalink)  
Old 02-04-12, 20:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT COUNT(*) AS distinct_count
  FROM ( SELECT DISTINCT
                ip
              , DATE(clickdate)
           FROM daTable
          WHERE clickdate >= '2012-01-01'
            AND clickdate  < '2012-02-01' ) AS t
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-04-12, 21:12
eagles396 eagles396 is offline
Registered User
 
Join Date: Dec 2006
Posts: 4
Thanks. How would you group by the Link so the query would look like below

Link Column, Count Column
Link 1, 10
Link 2, 20
etc..
Reply With Quote
  #4 (permalink)  
Old 02-04-12, 21:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT link
     , COUNT(*)
  FROM daTable
 WHERE clickdate >= '2012-01-01'
   AND clickdate  < '2012-02-01'
GROUP
    BY link
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-04-12, 22:17
eagles396 eagles396 is offline
Registered User
 
Join Date: Dec 2006
Posts: 4
sorry I meant all I need is the first query grouped by the link

Last edited by eagles396; 02-04-12 at 22:24.
Reply With Quote
  #6 (permalink)  
Old 02-04-12, 23:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
okay, now you've lost me

did you test the last query i gave you? how is it different than what you really wanted?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 02-06-12, 03:29
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
By the way you can also use:

SELECT COUNT(DISTINCT ip, clickdate)
FROM daTable
WHERE clickdate >= '2012-01-01'
AND clickdate < '2012-02-01'
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #8 (permalink)  
Old 02-06-12, 06:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by it-iss.com View Post
By the way you can also use:
only in mysql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 02-06-12, 06:14
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
and Oracle.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #10 (permalink)  
Old 02-06-12, 07:41
eagles396 eagles396 is offline
Registered User
 
Join Date: Dec 2006
Posts: 4
Quote:
Originally Posted by r937 View Post
okay, now you've lost me

did you test the last query i gave you? how is it different than what you really wanted?
Sorry I was looking for something like your first query which I have listed below but to also include the link column.

Code:
SELECT COUNT(*) AS distinct_count
  FROM ( SELECT DISTINCT
                ip
              , DATE(clickdate)
           FROM daTable
          WHERE clickdate >= '2012-01-01'
            AND clickdate  < '2012-02-01' ) AS t
Reply With Quote
  #11 (permalink)  
Old 02-06-12, 08:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by eagles396 View Post
...but to also include the link column.
what happened when you included the link column?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On