gpt4 book ai didi

sql - 仅选择满足 60% 的 where 子句的行 - SQL Server

转载 作者:行者123 更新时间:2023-12-02 08:00:58 25 4
gpt4 key购买 nike

我在 SQL 方面面临挑战。我有以下查询:

SELECT *
FROM Books
WHERE
Categories IN ('Fiction', 'art') OR
Language IN ('en', 'de') OR
Country = 'DE'

我需要查看结果,如果它们至少等于其中两个因素,则会被接受,而不是不会被选中。

例如如果一本书有 Category = FictionLanguage = FRCountry = DE

=> 通过

Category = HistoryLanguage = FRCountry = DE 的书

=>失败

我如何在 SQL 中实现它?

我试图计算每一行的权重。每个因素都会将 0.3 添加到完整权重中,并且只会选择具有 > 0.6

我也试过分组。但我真的找不到正确的语法。

有什么想法吗?谢谢!

附言我不能将所有可能性都放在 where 子句中,因为我有 3 个以上的因素。

最佳答案

select * from
(
SELECT *,
case when Categories in ('Fiction', 'art') then 1 else 0 end as cat_condition,
case when Language in ('en', 'de') then 1 else 0 end as lang_condition,
case when Country = 'DE' then 1 else 0 end as country_condition
FROM Books
WHERE
Categories in ('Fiction', 'art') OR
Language in ('en', 'de') OR
Country = 'DE'
) tmp
where cat_condition + lang_condition + country_condition >= 2

关于sql - 仅选择满足 60% 的 where 子句的行 - SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57345669/

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