仅允许作为顶级连词的 SubQuery 表达式错误

Only SubQuery expressions that are top level conjuncts are allowed error

我在配置单元中有以下 sql 运行,我想在其中使用一个查询的输出并将其用于 return = 值 returned。我收到一个错误;

错误 编译语句时出错:失败:SemanticException 行 0:-1 不支持的子查询表达式“1”:仅允许作为顶级连词的子查询表达式

SELECT * from database1.table1 
where FieldID = (
 select * 
FROM database1.table1
order by date/time DESC
limit 1) 

想法是子查询将 return highest/latest 最多记录。然后使用该记录查找相同的 table 和 return 所有与该 ID 关联的记录。

所以在下面的 table 中,你会看到它按 date/time 排序,子查询上的 return 应该是 8。使用 8 的输出,告诉我同一 table 中的所有记录,其中 FieldID = 8

数据Table

字段ID date/time
8 17/6 下午 1 点
2 17/6 中午 12 点
1 17/6 上午 11 点
2 17/6 上午 10 点
8 17/6 上午 9 点
4 17/6 早上 8 点
8 17/6 早上 7 点
1 17/6 早上 6 点
8 17/6 凌晨 5 点
8 17/6 凌晨 4 点

您可以使用 JOIN 代替:

select t1.*
from database1.table1 t1 join
     (select max(date_time) as max_date_time
      from  database1.table1
     ) tt1
     on tt1.max_date_time = t1.date_time;