select keytag,count(*) as num from keytags join (select id as did from keytags where keytag in ('test','key') ) as a on keytag not in ('test','key') and id = did and kprivacy = 5 group by keytag order by num limit 15表keytags 中有字段id,keytag,具体的要求看看SQL应该也就明白了

解决方案 »

  1.   

    select keytag,count(*) as num from keytags join (select id as did from keytags where keytag in ('test','key') ) as a on keytag not in ('test','key') and id = did and kprivacy = 5 group by keytag order by num limit 15感觉LZ的句子查询不出来结果的...
      

  2.   

    --试试
    select keytag,count(*) as num 
    from keytags join (select id as did from keytags where keytag in ('test','key')) as a 
                 on  id = did 
    where keytag not in ('test','key') and kprivacy = 5 
    group by keytag 
    order by num limit 15
    select keytag,count(*) as num 
    from keytags join keytags a on  id = a.id 
    where a.keytag in ('test','key') and keytags.keytag not in ('test','key') and kprivacy = 5 
    group by keytag 
    order by num limit 15--具体哪个更好应该看你的数据的具体情况
      

  3.   

    偶是用的mysql,limit相当与sqlserver的top,不过用的位置不一样就是了