简体   繁体   中英

mysql group by display unique count of columns

SELECT ip_address,datetime,DATE(datetime) as thedate, count(DATE(datetime)) as visits
FROM articleview_logtable 
GROUP BY DATE(datetime)

this query works great it returns how many rows for each date.I want a query to find out the total of rows for each day without counting ip duplicates. each row is inserted when someone visits the page that I made, the problem is if someonecomes back from the same ip I dont want to count them for that day as a new person.

Try using DISTINCT :

SELECT ip_address, COUNT(DISTINCT(ip_address)) as visits, datetime,DATE(datetime) as thedate, 
FROM articleview_logtable 
GROUP BY DATE(datetime)

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