I have a BigQuery table in which every row is a visit of a user in a country. The schema is something like this:
UserID | Place | StartDate | EndDate | etc ...
---------------------------------------------------------------
134 | Paris | 234687432 | 23648949 | etc ...
153 | Bangkok | 289374897 | 2348709 | etc ...
134 | Paris | 9287324892 | 3435438 | etc ...
The values of the "Place" columns can be no more than tens of options, but I don't know them all in advance.
I want to query this table so that in the resulted table the columns are named as all the possibilities of the Place column, and the values are the total number of visits per user in this place. The end result should look like this:
UserID | Paris | Bangkok | Rome | London | Rivendell | Alderaan
----------------------------------------------------------------
134 | 2 | 0 | 0 | 0 | 0 | 0
153 | 0 | 1 | 0 | 0 | 0 | 0
I guess I can select all the possible values of "Place" with SELECT DISTINCT but how can I achieve this structure of result table?
Thanks