-1

I got a output like by following

ID Name  Col1  Col2  Col3  
1  ABC    X     0     0
2  ABC    0     Y     0 
3  ABC    0     0     Z

I need this followed by

ID Name  Col1  Col2  Col3  
1  ABC    X     Y     Z

I tried group by Name but it is not working

  • Could you give us a little more information on what you've already tried? Putting your data in a more accessible format will further increase your chances of getting a helpful answer (reduce it to the minimum set needed, inline it in your question). – markusthoemmes Aug 24 '18 at 09:34
  • 1
    On the question itself: How do you envision the rows to be combined? A sample result of the query you're looking for will be helpful as well. – markusthoemmes Aug 24 '18 at 09:36
  • What rule do you want applied? Ignore digits and use letters only? Is that the rule? Or what else? And if that is the rule, what if there are two rows for the same name with contradictory letters? Which to choose? – Thorsten Kettner Aug 24 '18 at 09:49

2 Answers2

0

Try group by with aggrgation

select name, max(col1),max(col2),max(col3)
from tablename
group by name
Fahmi
  • 37,315
  • 5
  • 22
  • 31
0

If the 0s where NULL, then this should work:

select name, max(col1), max(col2), max(col3)
from tablename
group by name;

The 0s are rather confusing. This may be closer to what you want:

select name, max(nullif(col1, '0')),
       max(nullif(col2,'0')), max(nullif(col3, '0'))
from tablename
group by name;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786