-2

layout

https://www.dropbox.com/s/6fu81cqsl25vksd/layout.png?dl=0

link to image

Example:

Create Statement:

create table rating
(
  id int,
  tieid int,
  inspected datetime,
  rate varchar(50)
);

Insert Statement:

insert into rating values
(1,1, '0000-00-00 00:00:00', 'E'),
(2,1, '2015-03-31 01:01:22', 'G'),
(3,1, '2015-02-26 01:01:22', 'B'),
(4,2, '0000-00-00 00:00:00', 'E'),
(5,2, '2015-03-31 01:01:22', 'F');

What Im trying to do is get an ouput with this data like such cant seem to figure out how to get the query correct for this

tieid | inspected1 | rate1| inspected2 | rate2| inspected3 | rate3|
1     | 0000-00-00 |E       |2015-02-26 |B      | 2015-03-31 |G      |
2     | 0000-00-00 |E       |2015-03-31 |F       |                    |         |
-------------------------------------------------------------------

DominikAngerer
  • 6,354
  • 5
  • 33
  • 60

1 Answers1

0

doing this in a single query, is not really possible in MySQL, because mySQL does not have anything to feature something like that.

on this page there's a suggestion that this might be doable using prepared statements, and dynamic query generations: MySQL pivot table query with dynamic columns

In my opinion, this approach is pretty WTFey and personally I would not use it and take a multiple query approach instead.

Community
  • 1
  • 1
Matthias
  • 2,622
  • 1
  • 18
  • 29