0

I know there's a ton of Pivot questions, but every one I find seems to do some sort of SUM or COUNT operation, which is not what I need. I have a table like this:

id      field        val
---------------------------------
1234    type         Blade Server
1234    memory       24
1234    hostname     test_box1
4567    type         Blade Server
4567    memory       98
4567    hostname     test_box2
4567    ip           192.168.1.4

id is a foreign key that links field/val. What is in field is dynamic and not known ahead of time... it's basically a generic key/value pair store. (Which I can't change BTW... it's already set in the architecture). But I'm trying to create a pivot view that will take the above table and give me this:

id      type            memory  hostname    ip  
-------------------------------------------------------
1234    Blade Server    24      test_box1   NULL
4567    Blade Server    98      test_box2   192.168.1.4

Note that id 1234 does not have an "ip" field entry, so it needs to show up as NULL in the pivoted table. Basically, every "field" option should become a column, linked by "id". I guess this is an aggregation operation, but I couldn't figure how to make it work...

Any thoughts?

Adam Haile
  • 30,705
  • 58
  • 191
  • 286

0 Answers0