简体   繁体   中英

How to not count rows twice if they have same value in mySQL?

I have a visitor tracking system. I track visitor ips and browser. I can count total visits (total rows), but how can I count unique visits ?

您可以使用Distinct

SELECT Count(DISTINCT visits) from Table;

Use GROUP BY on IP, or IP+browser! SELECT COUNT(ip) FROM yourtable GROUP BY ip

Something like this will give you "unique visitors" as measured by distinct browser/IP hits:

SELECT COUNT(*) AS unique_visitors FROM (
    SELECT DISTINCT ip, browser FROM visitors
) a

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