日期:2014-05-18 浏览次数:20450 次
select Count(Distinct UserKey) FROM VisitLog110101 耗时近4分
SELECT count(distinct HashBytes ('md5',upper(UserKey))) FROM VisitLog110101
select UV=Count(UV) from ( select UV=1 FROM VisitLog110101 group by UserKey ) a
select count(*) FROM VisitLog110101 group by UserKey
------解决方案--------------------
唉,都没涉及到那么多数据的查询
------解决方案--------------------
如果UserKey上有索引,
直接count(*)应该很快.
------解决方案--------------------
select count(*) from (select distinct UserKey FROM VisitLog110101) a
------解决方案--------------------
UserKey字段是否真的唯一, 即没有重复值的?
如果是, 可以把索引修改为唯一索引(unique index),
这样distinct就很快了.