--SQL 1
select b.name,sum(a.vcount)as vcount
from t_sd_vxid a join dict.t_vinfo b on a.vxid = b.p_id
group by a.vxid
order by vcount desc
limit 20
--SQL 2
select b.name,t.vcount from
(select a.vxid,sum(a.vcount)as vcount
from t_sd_vxid a
group by a.vxid
order by vcount desc
limit 20)t
join dict.t_vinfo b on t.vxid = b.p_id
--注意一下2个语句的写法 查的结果相同 但第2个是比较优化的查询方式
--第一个中每一条记录都要匹配dict.t_vinfo 表
--第二个是统计后的记录再做匹配
--数据量大的时候第一个会把数据库资源占满[align=center][/align]
select b.name,sum(a.vcount)as vcount
from t_sd_vxid a join dict.t_vinfo b on a.vxid = b.p_id
group by a.vxid
order by vcount desc
limit 20
--SQL 2
select b.name,t.vcount from
(select a.vxid,sum(a.vcount)as vcount
from t_sd_vxid a
group by a.vxid
order by vcount desc
limit 20)t
join dict.t_vinfo b on t.vxid = b.p_id
--注意一下2个语句的写法 查的结果相同 但第2个是比较优化的查询方式
--第一个中每一条记录都要匹配dict.t_vinfo 表
--第二个是统计后的记录再做匹配
--数据量大的时候第一个会把数据库资源占满[align=center][/align]