比较两个不相关的表 sql
Compare two unrelated tables sql
我们正在使用我们的 Oracle 数据库处理地理数据。
有一个名为 ST_Insertects(x,y) 的函数,如果记录 x 与 y 相交,则 returns 为真。
我们要做的是,将table A的每条记录与table B的所有记录进行比较,并检查两个条件
condition 1 : A.TIMEZONE = 1 (Timezone field is not unique)
condition 2 : B.TIMEZONE = 1
condition 3 : ST_Intersects(A.SHAPE, B.SHAPE) (Shape field is where the geographical information is stored)
我们要查找的结果是 table A 中满足上述所有 3 个条件的记录
我们在单个 select 语句中尝试了这个,但它在逻辑上似乎没有多大意义
演示交叉连接的伪代码:
select A.*
from
tbl1 A, tbl2 B
where
A.TIMEZONE = 1 and
B.TIMEZONE = 1 and
ST_Intersects(A.SHAPE, B.SHAPE)
如果你得到倍数,你可以放置一个不同的并且只有 select A.XXX 列
使用交叉连接的行是这样匹配的
a.row1 - b.row1
a.row1 - b.row2
a.row1 - b.row3
a.row2 - b.row1
a.row2 - b.row2
a.row2 - b.row3
因此,如果第 1 行在多行上的计算结果为真,则只需在 a.Column1 等上添加一个不同的
如果您想在 Oracle SQL 语句中使用函数中的 return 值,您需要将函数更改为 return 0
或 1
(或 'T'/'F'
- Oracle 数据库支持的某些数据类型,不支持布尔数据类型)。
那么你可能想要这样的东西
select <columns from A>
from A
where A.timezone = 1
and exists ( select *
from B
where B.timezone = 1
and ST_intersects(A.shape, B.shape) = 1
)
我们正在使用我们的 Oracle 数据库处理地理数据。
有一个名为 ST_Insertects(x,y) 的函数,如果记录 x 与 y 相交,则 returns 为真。
我们要做的是,将table A的每条记录与table B的所有记录进行比较,并检查两个条件
condition 1 : A.TIMEZONE = 1 (Timezone field is not unique)
condition 2 : B.TIMEZONE = 1
condition 3 : ST_Intersects(A.SHAPE, B.SHAPE) (Shape field is where the geographical information is stored)
我们要查找的结果是 table A 中满足上述所有 3 个条件的记录
我们在单个 select 语句中尝试了这个,但它在逻辑上似乎没有多大意义
演示交叉连接的伪代码:
select A.*
from
tbl1 A, tbl2 B
where
A.TIMEZONE = 1 and
B.TIMEZONE = 1 and
ST_Intersects(A.SHAPE, B.SHAPE)
如果你得到倍数,你可以放置一个不同的并且只有 select A.XXX 列
使用交叉连接的行是这样匹配的
a.row1 - b.row1
a.row1 - b.row2
a.row1 - b.row3
a.row2 - b.row1
a.row2 - b.row2
a.row2 - b.row3
因此,如果第 1 行在多行上的计算结果为真,则只需在 a.Column1 等上添加一个不同的
如果您想在 Oracle SQL 语句中使用函数中的 return 值,您需要将函数更改为 return 0
或 1
(或 'T'/'F'
- Oracle 数据库支持的某些数据类型,不支持布尔数据类型)。
那么你可能想要这样的东西
select <columns from A>
from A
where A.timezone = 1
and exists ( select *
from B
where B.timezone = 1
and ST_intersects(A.shape, B.shape) = 1
)