gpt4 book ai didi

php - 在查询中连接两个 SQL 表

转载 作者:行者123 更新时间:2023-11-29 12:06:46 24 4
gpt4 key购买 nike

我有两个表(具有相同的模式)

Table1
id title D0 D1 D2 D3
------------------------------------
1 Title1 0.12 3.23 4.90 -0.12
1 Title1 0.22 0.32 -4.90 0.12
1 Title1 0.13 1.24 3.50 -0.22
...
1 TitleN 1.22 2.33 3.90 -1.56

Table2
id title D0 D1 D2 D3
------------------------------------
1 Title1 1.42 -0.93 -2.99 3.22
1 Title1 0.52 3.32 -4.90 0.54
1 Title1 2.13 1.14 3.50 -0.22
...
1 TitleN 3.42 4.37 3.90 -1.26

我正在尝试弄清楚如何进行查询,例如可以执行以下数学运算:

SELECT title FROM Table2 WHERE (Table1_Row1_D0*Table2_Row1_D0)+(Table1_Row1_D1*Table2_Row1_D1)+(Table1_Row1_D2*Table2_Row1_D2) < 0.5;

但是,我希望查询遍历 Table1 的行并对整个 Table2 执行 SELECT。基本上,我想从表 2 中选择满足表 1 和表 2 的所有行组合的计算不等式的标题。

这可能吗???

不确定这是否重要,但我正在使用 Postgre。

最佳答案

Basically, I want to select the titles from Table2 where the calculation inequality is met against ALL the row combination of Table1 and Table 2.

为此,您需要相反的条件,即 Table1 中不存在与 Table2 行相等的条件。

SELECT distinct title
FROM Table2
WHERE NOT EXISTS (
SELECT *
FROM Table1
WHERE (Table1.D0*Table2.D0)+(Table1.D1*Table2.D1)
+(Table1.D2*Table2.D2) >= 0.5
)

关于php - 在查询中连接两个 SQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4718548/

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