4

I want to perform the integration of an unspecified number of rows to one row in sql. I need a sql query to do this.

My view:

service_id  title   value
----------  -----   -----
1              A    10
1              B    20
1              C    40
2              A    15
2              B    72
2              C    70
.              D     .
.              F     .
.              .     .

Result I expected was:

service_id  A   B   C   D F ..
----------  -   -   -   - - ---
1          10   20  40  . . .
2          15   72  70  . . .
.
.

The number of fields is unknown ( A,B,C , ... )

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ehsan
  • 439
  • 3
  • 15

1 Answers1

1

If you want use this in MySQL you can use this

select service_id  , group_concat(`titlevalue` separator ',') as `your_fild_name` from ( select id, concat(`title`, ':',  group_concat(`value` separator ',')) as `titlevalue` from your_table_name group by id, `titlevalue`) tbl group by service_id  ;
AAZ
  • 51
  • 7