SELECT `time`,count(uid) as log
FROM (
SELECT distinct uid,
FROM_UNIXTIME(createtime,"%Y-%m-%d") as time FROM `yq_user_log`
WHERE `createtime` BETWEEN 1535126400 AND 1537891199 AND `type` = 'login'
) a GROUP BY time
答案 0 :(得分:1)
对于初学者来说,您甚至不需要子查询:
SELECT
FROM_UNIXTIME(createtime, '%Y-%m-%d') AS time,
COUNT(DISTINCT uid) AS log
FROM yq_user_log
WHERE createtime BETWEEN 1535126400 AND 1537891199 AND type = 'login'
GROUP BY time;
我不确定这里是否有任何索引会有所帮助,因为您是按列的功能分组的。这将排除索引对GROUP BY
的帮助。