在具有两行的两个表之间加入

Join between two tables with two rows

我有两个表:

Table答:

Name Value
ABC 95
XYZ 85

Table乙:

Category Value
MaxVal 90
MinVal 80

我想达到这个结果 85 是介于 80 和 90 之间的值,所以我们只过滤掉 XYZ 而不是 ABC :

Result
XYZ

我正在尝试如下:

SELECT Name as Result from TableA a, TableB b, TableB c 
where a.value < b.value and a.value > c.value 
and b.value=c.value and 1=1;

有更好的方法吗?

删除 b.value=c.value,它会过滤掉表 bc 中的所有记录和 select 正确类别:

SELECT Name as Result from TableA a, TableB b, TableB c 
where a.value < b.value and b.category = 'MaxVal'
and a.value > c.value and c.category = 'MinVal';

这是另一个选项,在我看来更具可读性:

SELECT Name as Result FROM TableA
 WHERE a.value > (SELECT value FROM TableB WHERE category = 'MinVal')
   AND a.value < (SELECT value FROM TableB WHERE category = 'MaxVal');