gpt4 book ai didi

mysql - 根据条件检索值

转载 作者:行者123 更新时间:2023-11-29 13:00:20 25 4
gpt4 key购买 nike

请查看以下查询。

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 中做到这一点?上次我这样做时,它给我抛出了一个错误,类似于 Invalid use of Group function

最佳答案

你试过这个吗?

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;

聚合函数结果的条件属于 having 子句,而不是 where 子句。

关于mysql - 根据条件检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23436180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com