mysql - Combine two similar rows into one with new columns -
original table:
name age contact_type contact alex 20 sms 12345 alex 20 email abc@gmail.com alex 20 sms 54321 bob 35 sms 23456
i want make as:
name age contact_type1 contact_1 contact_type2 contact_2 contact_type3 contact_3 alex 20 sms 12345 email abc@gmail.com sms 23456 bob 35 sms 23456
if name , age duplicated, combine 2(or more) rows 1 row new column shown above.
i want finding same 'name' , 'age', , using distinct contact case when count distinct(contact)>0
seems many syntax error occur. there smarter method make it?
use conditional aggregate
this
select name,age, max(case when contact = 'sms' contact end) contact_1, max(case when contact = 'email' contact end) contact_2 yourtable group name, age
Comments
Post a Comment