2016-05-16 92 views
0

我有一个表event。这就好比:将行转换为列

user_id feature_name feature_value 
    1   launced   yes 
    1   voice_enabled no 
    1   trim_used  yes 
    1   voice_enabled yes 
    1   trim_used  yes 
    2   launched   yes 
    2   voice_enabled no 
    2   trim_used  no 
    2   voice_enabled yes 
    2   zoom_used  yes 

有行的千像这样和在feature_name列可以有更多的功能被添加如果有用户会使用它。

我必须以更有意义的格式转换此表,其中每个feature_name将作为单独列并具有特定用户使用的功能数。

所以输出表如下所示:

user_id launched voice_enabled trim_used zoom_used 
    1   1   1    2   0 
    2   1   1    0   1 

任何帮助将非常感激。我正在使用PostgreSQL。

+0

你需要新表或只处理他们utize –

+0

两者都将被罚款。 –

+1

https://stackoverflow.com/search?q=[postgresql]+rows+to+columns或https://stackoverflow.com/search?q=[postgresql]+crosstab或https://stackoverflow.com/search q = [PostgreSQL的] +枢轴 –

回答