How to use MAX() on a subquery result?

后端 未结 7 1824
名媛妹妹
名媛妹妹 2021-02-07 08:48

I am new to Oracle and the SQL world. I have a slight issue with a query that I cannot figure out for the life of me, I have spent a few hours trying different approaches and I

7条回答
  •  有刺的猬
    2021-02-07 09:34

    I think the cleanest solution is to use the ALL comparison condition. It is used to compare a value to a list or subquery.

    SELECT 
      m.mem_desc,
      m.mem_max_rentals,
      mh.mem_type,      
      COUNT(mh.mem_type) as membership_count
    FROM membership_history mh
    JOIN membership m ON m.mem_type = mh.mem_type
    GROUP BY mh.mem_type,m.mem_desc,m.mem_max_rentals
    HAVING membership_count >= ALL (
      SELECT count(*)
      FROM membership_history
      GROUP BY mem_type
    )   
    

提交回复
热议问题