I have a table like:
userid cityid
1 4
1 5
2 4
2 1
3 1
3 5
Is there a way in SQL or hive to transform it into a table like:
userid city1 city4 city5
1 false true true
2 true true fase
3 true false true
I am not sure there is a word to describe this kind of operation…
Any help would be appreciated!
This is basically a
PIVOT. You did not specify what RDBMS you are using but you can use an aggregate function and aCASEstatement to get the results in any DB:See SQL Fiddle with Demo
Results: