0

I have one table with these value

col1                    col2                 col3         
----------------------  -------------------  -------------------------
                     1                    0  ADD SERVICE ACTIVITY 1   
                     0                    1  ADD SERVICE ACTIVITY 1   
                     0                    8  Docment testing 2 (C07) 

I want result like:

col1                    col2                 col3         
----------------------  -------------------  -------------------------
                     1                    1  ADD SERVICE ACTIVITY 1   
                     0                    8  Docment testing 2 (C07) 
barbsan
  • 3,418
  • 11
  • 21
  • 28
S. gupta
  • 1
  • 4
  • What if the second record not had `ADD SERVICE ACTIVITY 1` but `ADD SERVICE ACTIVITY 2` instead? would it still merge into one record like that? – Raymond Nijland Jan 17 '19 at 12:58
  • Somehow a [pivot](https://stackoverflow.com/questions/7674786/mysql-pivot-table) comes to mind to get the max of the col1 and col2 columns.. But hard to answer without some more records in the example data or how it should merge when the col3 is different between records. – Raymond Nijland Jan 17 '19 at 13:07
  • Do you mean any of [these queries](https://www.db-fiddle.com/f/dCqySHzLjRER7PiGWEPEb8/0)? – barbsan Jan 17 '19 at 13:30

1 Answers1

0

It seems that you want to group your data by column col3. I'm not sure whether results for col1 and col2 are sums or max values.

--for MAX:
SELECT MAX(COL1) as col1, MAX(COL2) as col2, COL3
/*-- for SUM:
SELECT SUM(COL1) as col1, SUM(COL2) as col2, COL3
*/
FROM test
GROUP BY COL3;
barbsan
  • 3,418
  • 11
  • 21
  • 28