2017-08-09 89 views
0

enter image description here只能从某些行

select name from myschema.table1 where 
COL1 = 'A'and 
COL2= 'B' and 
LEVEL = (select max(LEVEL) from myschema.table1 where USERTYPE='C') 

我知道我对查询表中的最高水平,而不是与用户类型“C”行中的最大电平选择一列的最大值。我只需要针对那个usertype进行查询。

回答

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' 
      );