【问题标题】:select max value of a column only from certain rows仅从某些行中选择列的最大值
【发布时间】:2017-08-09 15:05:16
【问题描述】:

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

我知道查询的是表中的最高级别,而不是 userType 为“c”的行中的最高级别。我只需要查询具有该用户类型的用户。

【问题讨论】:

    标签: mysql sql select subquery inner-join


    【解决方案1】:

    你很亲密。你需要一个关联子句:

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

    【讨论】:

      猜你喜欢
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多