Reputation: 549
If I have a table like this:
id | vid | cid | ipaddress
1 | 1 | 1 | 1.1.1.1
2 | 1 | 1 | 1.1.1.1
3 | 1 | 1 | 1.1.1.2
4 | 2 | 1 | 2.2.2.2
5 | 2 | 1 | 2.2.2.2
6 | 2 | 1 | 2.2.2.2
vid is visitor id and cid is campaign id
If visitor visits campaign the visit gets captured to table. I want to then display a the number of unique visits, not based on user, but on user and ip. So for the data above it's 2 users and 1 of the users visited with 2 different ip addresses, so how do i do a select query to select distinct visitors, but count the visitors multiple times if they used multiple ip addresses? The total number that should display for above captured data is 3 unique visits.
Upvotes: 1
Views: 1785
Reputation: 2229
Well you can try this :-
SELECT vid, count(distinct(IP)) AS dstn from test
Upvotes: 3
Reputation: 37023
Try something like:
SELECT vid, COUNT(DISTINCT ipaddress) AS ip_address_count
FROM mytable
GROUP BY vid
Upvotes: 1