ecshop高效SQL查询数据库

2011-08-11 13:13 来源:www.chinab4c.com 作者:ecshop专家

1:高效的查询商品销售表中,排名前200的商品


select * from(select goods_name,sum(goods_number)  as gc from ecs_order_goods group by goods_name   )  t order by gc desc limit 200

select goods_name ,sum(goods_number) gc  from ecs_order_goods group by goods_name  order by gc desc limit 200

2:删除重复IP的 session

$this->db->query("delete a from ".$this->session_table." a inner join(select ip from ".$this->session_table." group by ip having(count(ip))>200) b on a.ip = b.ip");