Skip to content
Advertisement

mysql group 2 rows into 1 with only one different value between the rows

I currently have this query:

which gives me this table:

club_name km type
A 10 1
A 15 2
B 80 1
B 34 2
C 36 1

And I’m trying to achieve:

club_name type 1 km type 2 km
A 10 15
B 80 34
C 36

not all clubs will have a type 2. How do I rewrite the query to achieve the reorganization?

Advertisement

Answer

You can use conditional aggregation:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement