MySQL Query to Count Unique Domains from Email Address field

后端 未结 7 1851
执念已碎
执念已碎 2020-12-13 02:16

I\'d like to get a better idea of what domains my customers are using. I could easily do this in PHP by explodeing each address and counting the domain that way

7条回答
  •  清歌不尽
    2020-12-13 02:53

    You would have to do something like this:

    SELECT substring_index(email, '@', -1) domain, COUNT(*) email_count
    FROM table
    GROUP BY substring_index(email, '@', -1)
    
    -- If you want to sort as well:
    ORDER BY email_count DESC, domain;
    

提交回复
热议问题