我有两个SQLite表t1
和t2
,它们具有相同的字段:name
,value1
,value2
,value3
。>
至关重要的是,(a)表t1
仅包含单个记录John|20|19|4
,而(b)该记录可能会更改。
我想从T2中选择所有那些记录,其中t2.value1 <= t1.value1(即,唯一记录中的单个t1.value1)和t2.value2 <= t1.value2和t3.value3。这可能吗?
答案 0 :(得分:1)
这应该做到:
select *
from T2
where exists
( select *
from T1
where T2.Value1 <= T1.Value1 and
T2.Value2 <= T1.Value2 and
T2.Value3 <= T1.Value3
)
答案 1 :(得分:0)
是的,有可能。您可以尝试以下查询
WITH (SELECT TOP(1) FROM table t1 AS record),
SELECT * FROM table t2 WHERE t2.value1 <= record.value1 AND t2.value2 <=
record.value2 AND t3.value3 <= record.value3;