I need to do what I thought was going to be a simple SQL query.. but I got stuck deciding how can these be grouped:
<p>I've got the below table:</p>
Company | Airport | Type
------------------------------------------
SP1 | AP1 | ST1
SP1 | AP1 | ST2
SP1 | AP1 | ST3
SP1 | AP2 | ST1
SP1 | AP2 | ST2
SP1 | AP2 | ST3
SP1 | AP3 | ST1
SP1 | AP3 | ST2
SP1 | AP4 | ST1
SP1 | AP4 | ST2
SP1 | AP4 | ST3
SP1 | AP4 | ST4
I want to group AP
and ST
in the following way so that the desired result is like this:
(CASE 1)
SP | AP | ST
------------------------------------------
SP1 | AP1, AP2, AP4 | ST1, ST2, ST3
SP1 | AP3 | ST1, ST2
SP1 | AP4 | ST4
Any thoughts? Really appreciated!
Update
As pointed out, there is another alternative for the result:
(CASE 2)
SP | AP | ST
------------------------------------------
SP1 | AP1, AP2 | ST1, ST2, ST3
SP1 | AP3 | ST1, ST2
SP1 | AP4 | ST1, ST2, ST3, ST4
I've also added titles to the columns to give a bit more context. The idea is just that, to be able to group associated elements. I'm happy with any of the two results, hopefully both alternatives if possible..