SQL 查询同一个多列的 where 子句 table

SQL Query where clause for multiple columns in same table

具有以下数据库:

正在尝试执行以下查询:

select * 
from data_five_minutes 
where ((open in (select open 
                 from data_five_minutes 
                 where date_time = '2019-01-02 13:15:00')) > 
        (open in (select open 
                  from data_five_minutes 
                  where date_time = '2019-01-01 11:10:00')))

上面的查询给了我结果给我 3 个结果,但我期待 0!

我尝试获取的是:- 获取 02/01 的开盘价 13:15 > 01/01 的开盘价 11:10 两者 script_id 相同的行。

您可以使用 EXISTS:

SELECT d1.* 
FROM data_five_minutes d1 
WHERE d1.date_time = '2019-01-02 13:15:00'
  AND EXISTS (
    SELECT 1
    FROM data_five_minutes d2
    WHERE d2.date_time = '2019-01-01 11:10:00'
      AND d2.script_id = d1.script_id
      AND d2.open < d1.open
  );