Skip to content
Advertisement

SQL: how to pivot dimensions in a column?

I’m looking to do the following:

Raw table: this has just two articles, their traffic channels, and unique pageviews

Returns:
enter image description here

I want to return a table that looks like this: enter image description here

Here’s my current solution – which I think is inelegant and slow. There’s surely an easier way to do this in BigQuery SQL (note – I don’t have a pivot function I can use)

Advertisement

Answer

There is a much simpler way to do this using a pivot query with conditional aggregation:

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