user2115506 user2115506 - 2 months ago 23
MySQL Question

Mysql -> joinin two rows in output

My table consist of this below

Country | Type | A | B | C | D | cType
------------------------------------------------------------------
Italy | Foreign | | | C | D | Commercial
Italy | Foreign | A | B | | | Commercial
Italy | Local | | | C | D | Gov
Italy | Local | A | B | | | Gov


I want to do a query that out put the result like below, using the type

Italy | Foreign | A | B | C | D | Commercial
Italy | Local | A | B | C | D | GOV

Answer
select country, type, max(A), max(B), max(C), max(D), cType
from whatever_table
group by country, type, cType