create database if not exists v; drop table if exists v.t1; create table v.t1 (c1 int, c2 string, c3 int) stored as parquet; insert into v.t1 values (1,'aa',2), (1,'b',4), (10,'b',2), (1,'ar',2), (1,'a', 4); drop table if exists v.t2; create table v.t2(c1 int, c2 int) stored as parquet; insert into v.t2 values(1,2), (1,3), (1,4), (4,4), (5,10), (5,12), (6,8), (19999,3); drop view if exists v.v1; create view v.v1 as with iv1 AS (SELECT c1, c3 FROM v.t1 group by c1, c3), iv2 AS (SELECT c1 r_c1, max(c3) max_c3 FROM v.t1 group by r_c1) select iv1.c3, iv2.max_c3 FROM iv1, iv2 where iv1.c3 = iv2.max_c3;