gupta24 Posted March 14, 2016 Report Posted March 14, 2016 Col1 col2 23 121 23 123 24 125 25 127 25 124 Epudu col1lo 23 ane value multiple times repeat ayindi so apudu col 2 null ipovali. Result should be like this: Col1 col2 23 Null 23. Null 24. 125 25. Null 25. Null Plss help
vikuba Posted March 14, 2016 Report Posted March 14, 2016 find the ids that repeating first Then take those ids and join to original table to create a case statment for ur condition
jaffanajeffada Posted March 14, 2016 Report Posted March 14, 2016 SELECT COL1, CASE WHEN COUNT (1) OVER (PARTITION BY COL1 ORDER BY COL1) > 1 THEN NULL ELSE COL2 END AS COL2 FROM (SELECT 23 AS COL1, 121 AS COL2 FROM DUAL UNION ALL SELECT 23 AS COL1, 123 AS COL2 FROM DUAL UNION ALL SELECT 24 AS COL1, 125 AS COL2 FROM DUAL UNION ALL SELECT 25 AS COL1, 127 AS COL2 FROM DUAL UNION ALL SELECT 25 AS COL1, 124 AS COL2 FROM DUAL) TAB
Uchiha Posted March 14, 2016 Report Posted March 14, 2016 case statement rayi..case when col1 >1 then 'null' else col1 end
parabramha Posted March 14, 2016 Report Posted March 14, 2016 Use count(col2) over (partition by col1 ) functions . If the Rank is >1 then make the second column null else leave it as is . select t.col1, case when t.no_of_rows=1 then t.col2 else null end new_col2 from ( select col1, col2, count(col2) over (partition by col1 ) no_of_rows from Table A ) t1 Hope it helps. Col1 col2 23 121 23 123 24 125 25 127 25 124 Epudu col1lo 23 ane value multiple times repeat ayindi so apudu col 2 null ipovali. Result should be like this: Col1 col2 23 Null 23. Null 24. 125 25. Null 25. Null Plss help
loveindia Posted March 15, 2016 Report Posted March 15, 2016 1) first in a cte get the counts = 1 man 2) below that use that CTE with exists clause and get all the values 3) rest all nulls man... not at my kemputer to write query man...
afdbzindabad Posted March 15, 2016 Report Posted March 15, 2016 Col1 col2 23 121 23 123 24 125 25 127 25 124 Epudu col1lo 23 ane value multiple times repeat ayindi so apudu col 2 null ipovali. Result should be like this: Col1 col2 23 Null 23. Null 24. 125 25. Null 25. Null Plss help baaaa endi query lu aipoledaaa inka
CheGuevara Posted March 15, 2016 Report Posted March 15, 2016 with x as (select col1 from (select col1, count(col1) cnt from table group by col1) where cnt > 1) select col1, case when col1 in (select col1 from x) then null else col2 from table;
loveindia Posted March 15, 2016 Report Posted March 15, 2016 with x as (select col1 from (select col1, count(col1) cnt from table group by col1) where cnt > 1) select col1, case when col1 in (select col1 from x) then null else col2 from table; Why subquery on top of it when you can achieve the same with one query man?? Also do you think case is needed in the case?
CheGuevara Posted March 15, 2016 Report Posted March 15, 2016 Why subquery on top of it when you can achieve the same with one query man?? Also do you think case is needed in the case? Emo mama... Oka query multiple ways lo rayachu... Naaku teliyakunda repu inko type lo rastanemo query... Edo sql query meeda thread chudagane edi rasesa...
manjunath455 Posted March 15, 2016 Report Posted March 15, 2016 with x as (select col1 from (select col1, count(col1) cnt from table group by col1) where cnt > 1) select col1, case when col1 in (select col1 from x) then null else col2 from table; gp
Recommended Posts