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应该也就明白了
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--具体哪个更好应该看你的数据的具体情况