select name from myschema.table1 where
COL1 = 'A'and
COL2= 'B' and
LEVEL = (select max(LEVEL) from myschema.table1 where USERTYPE='C')
我知道正在查询表中的最大级别,而不是使用userType“c”的行中的最大级别。我只需要查询具有该usertype的那些。
答案 0 :(得分:2)
你非常接近。您需要一个关联子句:
select t.name
from myschema.table1 t
where COL1 = 'A'and COL2= 'B' and
LEVEL = (select max(t2.LEVEL)
from myschema.table1 t2
where t2.col1 = t.col1 and g2.col2 = t.col2 and t2.USERTYPE = 'C'
);