Mysql 基于条件检索值

Mysql 基于条件检索值,mysql,sql,select,group-by,where-clause,Mysql,Sql,Select,Group By,Where Clause,请看下面的查询 SELECT `p_id`, COUNT(`p_id`) AS OverlapWords, `UniqueWordCount`, (COUNT(`p_id`)/`UniqueWordCount`) AS SimScore FROM `key_uniqueword` WHERE `word` IN ('stand','on') GROUP BY (`p_id`) LIMIT 500 我需要将SimScore转换为百分比,并获取SimScore小于90%的所有记录。如何在SQL

请看下面的查询

SELECT `p_id`, COUNT(`p_id`) AS OverlapWords, `UniqueWordCount`, 
(COUNT(`p_id`)/`UniqueWordCount`) AS SimScore FROM `key_uniqueword` WHERE `word` IN 
('stand','on') GROUP BY (`p_id`) LIMIT 500
我需要将
SimScore
转换为百分比,并获取
SimScore
小于90%的所有记录。如何在SQL中实现这一点?上次我这么做的时候,它给我带来了一个错误,比如说
组函数的无效使用

你试过吗

SELECT `p_id`, COUNT(`p_id`) AS OverlapWords, `UniqueWordCount`, 
       (COUNT(`p_id`)/`UniqueWordCount`) AS SimScore
FROM `key_uniqueword`
WHERE `word` IN ('stand','on')
GROUP BY (`p_id`)
HAVING SimScore < 0.9
LIMIT 500;
选择'p\u id',COUNT('p\u id`)作为重叠词,'UniqueWordCount`,
(COUNT(`p_id`)/`UniqueWordCount`)作为核心
来自'key_uniqueword`
其中'word'在('stand','on')中
分组依据(`p_id`)
具有小于0.9的核心
限500;
聚合函数结果的条件属于
having
子句,而不是
where
子句