2016-05-16 81 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的] +樞軸 –

回答