I need to get the id of the folder, in which all file statuses are 3.

file_id status folder_id 1 3 1 2 1 2 3 3 1 4 3 1 5 3 2 

That is, all the files in the folder_id folder 1, status is 3. And in the folder folder_id 2, not all have status 3. Therefore, I need to return the request folder_id equal to 1. I don’t know where to dig, this is somehow related to grouping?

    1 answer 1

     select folder_id from tab group by folder_id having max(status)=3 and min(status)=3 
    • one
      And if the status can be null ? - Yaant
    • 2
      @Yaant then add another condition count(1)=count(status) - Mike