Hive 如何克服CASE语句配置单元中的子查询

Hive 如何克服CASE语句配置单元中的子查询,hive,hiveql,hadoop2,Hive,Hiveql,Hadoop2,如果条件为true,则必须将列值填充为“Y”,否则为“N”。但正如在配置单元中一样,它不支持case stetement中的子查询,如何在配置单元中返回它 (case when exists (select 1 from fntable fs join dfntable dfs on fs.id = dfs.id and dfs.datetime = (select max (cd.datetime) from dfntable cd group

如果条件为true,则必须将列值填充为“Y”,否则为“N”。但正如在配置单元中一样,它不支持case stetement中的子查询,如何在配置单元中返回它

(case
  when exists
  (select 1
  from fntable fs
  join dfntable dfs
  on fs.id = dfs.id
  and dfs.datetime = 
     (select max (cd.datetime)
      from dfntable cd group by id)
  and fs.s_id = dfs.s_id)  then 'Y'
else 'N')"

使用具有分析函数+左联接的子查询。当加入时,则为“Y”:

select case when cd.id is not null then 'Y' else 'N' end 
  from fntable fs
      left join
      ( --group by  cd.id, cd.s_id and filter 
       select cd.id, cd.s_id 
         from
            ( select max (cd.datetime) over (partition by dc.id) as max_id_datetime,
                     cd.id, cd.s_id, cd.datetime
                from dfntable cd
            ) cd
        where cd.datetime=max_id_datetime --filter only records with max date
        group by cd.id, cd.s_id
      ) cd on fs.id = dfs.id and fs.s_id = dfs.s_id

请提供两个表的数据示例和所需的输出示例