ankit ankit - 4 months ago 11
MySQL Question

Find number of users count in a day who visit the url

I need a query to fetch 'number of different users count' in a day who visit the url. This is structure of my table
enter image description here

And i try this query

SELECT DISTINCT `userid`,`url`, FROM_UNIXTIME(`time`,'%Y-%m-%d') as date,count(`userid`) as usercount FROM `mdl_log` GROUP BY FROM_UNIXTIME(`time`,'%Y-%m-%d')


but it not work. Please help me to correct this query.

Answer

use disinct and count together

SELECT count(DISTINCT `userid`) as usercount,`url`, FROM_UNIXTIME(`time`,'%Y-%m-%d') as date FROM `mdl_log` GROUP BY FROM_UNIXTIME(`time`,'%Y-%m-%d')