要统计本月活跃用户在次月的活跃情况,由于表太大,如果是简单的写一个:select count(distinct id) from a where exists (select 1from a where id=id)查询会比较慢。假如先把用户 groupby 下,再统计,时间会缩短为原来的10%左右。亲测可以。
select count(1)from (
select id from a group by id ) tt where exists (select 1 from (select id from a group by id ) aa where tt.id=aa.id)
sql利用groupby 提高查询效率
最新推荐文章于 2023-12-27 17:17:07 发布