简体   繁体   中英

count based on two columns in Mysql

My table in Mysql is like this:

 IP       ID     area
 aaa      A        I
 aaa      A        I
 aaa      B        I  
 aaa      C        II
 bbb      A        I
 bbb      B        III
 ccc      B        I

Now I want to calculate for each area value, how many different (IP, ID) pairs are there?

How can I use both IP and ID as a whole dataset to do this?

I don't think the following query is correct:

SELECT area, count (distinct IP, ID) from video GROUP BY area ORDER BY COUNT (distinct ip, ID)

So does anyone know how to do it?

SELECT count(*), CONCAT_WS(' ',IP,ID) as yourTitle FROM video GROUP BY yourTitle

应该做

SELECT area, count(*) as distinctCount FROM 
  (SELECT DISTINCT IP, ID, area FROM video) distinctVideos 
GROUP BY area
ORDER BY count(*)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM