0

Hi I am trying to create a mysql query that will convert multiple rows in a table to unique columns

The data I have is as follows:

DB table

The table I would like to see is as follows:

GEID|Username|First Name|Last Name|Email|Country|Dealer Code
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Danny Younes
  • 579
  • 1
  • 6
  • 19

2 Answers2

0

The statement which could be used is

UPDATE table_name
SET column1 = value 1 , column 2 = value 2 ...
Where condition;

Sorry but my SQL isn't the best but hope the statement helps

0

This is a real pain, because you don't have an id identifying groups that are the same. In other words, you are missing the entity id.

I think you can construct one by counting the number of GEID values before any given row. The rest is just aggregation:

select max(case when fieldname = 'GEID' then fieldData end) as GEID,
       max(case when fieldname = 'Username' then fieldData end) as Username,
       . . .
from (select t.*,
             (select count(*) from t t2 where t2.id <= t.id and t2.fieldName = 'GEID'
             ) as grp
      from t
     ) t
group by grp;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786