MySQL pivot row into dynamic number of columns
问题 Lets say I have three different MySQL tables: Table products : id | name 1 Product A 2 Product B Table partners : id | name 1 Partner A 2 Partner B Table sales : partners_id | products_id 1 2 2 5 1 5 1 3 1 4 1 5 2 2 2 4 2 3 1 1 I would like to get a table with partners in the rows and products as columns. So far I was able to get an output like this: name | name | COUNT( * ) Partner A Product A 1 Partner A Product B 1 Partner A Product C 1 Partner A Product D 1 Partner A Product E 2 Partner B