本帖最后由 lonsoft 于 2011-10-23 00:00:12 编辑

解决方案 »

  1.   

    select pid
    from 表结构如下
    where did in (1,5,6)
    group by pid
    order by count(*)
      

  2.   

    谢谢 ACMAIN_CHM :)不要用IN 吧。效率太低了。因为这个表有超过几百万条的数据。。
      

  3.   


    http://topic.csdn.net/u/20090626/16/65f043cf-b9d9-4707-b660-9857461177f4.html
    MySQL   中   where   id   in   (1,2,3,4,...)   的效率问题讨论
      

  4.   

    select pid
    from (
    select pid from TEST where did=5 
    union all
    select pid from TEST where did=6
    union all
    select pid from TEST where did=1
    )
    group by pid
    order by count(*) DESC用这种会不会效率高点呢?
      

  5.   


    另外请教一个问题,mysql 如果存在就不插入,用什么语句效率最高呢? :)
      

  6.   

    insert igonre ,如果主键冲突,则不会插入。