oracle10g - Oracle SQL query to return row values if all rows have some value in column after grouping by another column -


I have some data that looks like this -

  Cola ColB ColC ID1 1 '1 -1' ID 2 1 '2-1' ID 2 0 '2-2' ID 3 1 '3-1' ID 3 1 '3-2   

Give me a query (For Oracle 10G) that group gets the rows from the value of the cola and only then the values ​​of the calls are returned if all the rows in the group have ColB = 1, so for the given data I want the output Anyone -

  "1-1" "3-1,3-2"   

How to write a question like this?

Thank you!

  select cola, column_name WHERE colb = 1 group from wm_concat (ColC) From;  Edit  - You can also use the LISTAGG total function like this:  
  SELECT colA, LISTAGG (colc, ',') inside the group ( Order by CLC) from table_name to WHERE colb = 1 group by cola;   

I recommend using LISTAGG as it is documented by Oracle, while wm_concat is not.

Edit: If so, you do not want to show lines like ID2 because it is Colb = 0, or, colb! There is a line with = 1, you can:

  SELECT colA, from wm_concat (ColC) to table_name t1 where not found (select 1 from table 1, where colle! = 1 - Or, you can make colb = 0 and t2. cola = T. 1. cola) by cola cola    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -