I have a table which contains the following columns:
UniqueID
remote_ip_addr
platform
I want to create a query, which basically shows each IP address just once from each platform and count how many distinct platform entries there are
SELECT platform, COUNT(platform)
FROM fuckedapps_dm_appdl dm
GROUP BY platform
ORDER BY COUNT(platform) DESC
So for example from the following table:
uniqueID---remote_ip_addr----platform
1 20.15.1.234 iPhone
2 20.15.1.234 iPhone
3 20.15.1.234 iPhone
4 20.15.1.234 Android
5 20.15.1.234 Android
I’ll get the following result:
platform----COUNT(platform)
iPhone 1
Android 1
Right now I get the following:
platform----COUNT(platform)
iPhone 3
Android 2
Because they’re all the same ip, I want to get only 1 distinct value…
Thank you for your help.
edit: I should have mentioned that there’s another field, which is called app_id.
So the table is more like:
uniqueID---remote_ip_addr----platform---app_id
1 20.15.1.234 iPhone 23
2 20.15.1.234 iPhone 23
3 20.15.1.234 iPhone 18
4 20.15.1.234 Android 24
5 20.15.1.234 Android 25
in this case, I want the result to be:
platform----COUNT(platform)
iPhone 2
Android 2
Thank you, and sorry because I didn’t think it was relevant and now I see it is.
If I understand correctly, you want for every platfrom, the number of distinct IP addresses. Then you can use this. Note the
COUNTing ofDICTINCT remote_ip_addrfor every (GROUP BY) platform:After OP’s update. (it’s not good practise to alter the question by the way).
It’s not clear if you want distinct app_ids for every platfrom:
or distinct combinations of (app_id,remote_ip_addr)s for every platfrom:
Depends on what the wanted result is, say if you had one more row: