mysql - SQL query to identify pairs with duplicates -


i'm trying write query pair impressions , conversions same ip address in database. have table of impressions , ip addresses, , impression can of type 'view' or 'conversion' (defined in column 'name').

so basically, need identify groups of records same ip address, contain both view , conversion.

after hour of googling i've got far below, isn't far should give idea of objects involved:

select ip_address, name, count(1) cnt  impressions group ip_address, name; 

can advise on best way this?

you need use having clause conditional count. need remove name group by treat 2 different types separately.

select  ip_address,          count(case when name = 'view' 1 end) views,         count(case when name = 'conversion' 1 end) conversions,         count(1) cnt     impressions group ip_address having  count(case when name = 'view' 1 end) > 0 ,     count(case when name = 'conversion' 1 end) > 0; 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -