create view category_pc as 
select c.category_id p_id, cp.parent_id c_id, c.from  
from category c, category_parent cp  
where c.category_id = cp.category_id && c.type='p' && ((c.from >= '".$sel_date_from."' && c.from <='".$sel_date_to."')
继续找父亲,又生成一个临时表
create view category_pcs as 
select c_pc.p_id, c_pc.c_id, cp.parent_id s_id, c_pc.from, c.name s_name  
from category_pc c_pc, category_parent cp, category c  
where c_pc.c_id=cp.category_id && cp.parent_id=c.category_id";
继续找父亲,又生成一个临时表
create view category_pcsb as 
select c_pcs.p_id, c_pcs.c_id, c_pcs.s_id, cp.parent_id b_id, c_pcs.s_name, c_pcs.from, c.name b_name
from category_pcs c_pcs, category_parent cp, category c  
where c_pcs.s_id=cp.category_id && cp.parent_id=c.category_id";

解决方案 »

  1.   

    你是怎么觉得效率低下的?贴出你的explain select ..结果。
      

  2.   

    sixfish (第六条鱼(其实我只是出来混饭的)
      '截至2011-03-01 20:04:44    未结帖:14  当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  3.   

    id  select_type  table  type  possible_keys  key     key_len  ref  rows  Extra  
    1   SIMPLE       cp     index PRIMARY        PRIMARY  8       NULL 313984 Using index 
    1   SIMPLE       c      eq_ref PRIMARY,c_category_id_from,c_from PRIMARY 4 stylife.cp.category_id 1 Using where 
      

  4.   

    楼上EXPLAIN的哪一句?问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧