0

私はこのパズルを解決するために長い間検索しています。

次のようなmysqlテーブルがあります。

**id | role     |**  
--------------------
   1 | staff    |  
   1 | member   |  
   1 | paying   |  
   2 | staff    |  
   2 | admin    |  

私は約 35 種類のデータを役割として持っています。私が欲しいのは、役割のあらゆる種類のデータの列なので、このようなものになります。

**id | staff | member | paying | admin |**  
------------------------------------------
   1 | staff | member | paying | null  |  
   2 | staff | null   | null   | admin |  

それが役立つ場合、CASEを使用して行を作成することにすでに成功していますが、今の問題は、同じIDで複数の行を取得することです。そして、それらを 1 つに結合する必要があります。これまでのところ、group by を使用してみましたが、機能していません。

私がこれを使った列を作るために

create table ahbtest2 as (
  select
    ahbtest1.*,
    case when f_name = "newsletter" then f_name end as f_newsletter,
    case when f_name = "staff" then f_name end as f_staff,
    case when f_name = "Musician" then f_name end as f_musician,
    case when f_name = "No_membership" then f_name end as f_no_membership,
    case when f_name = "Beirut" then f_name end as f_beirut,
    case when f_name = "VISA" then f_name end as f_visa,
    case when f_name = "3wc" then f_name end as f_3wc,
    case when f_name = "Intl_media" then f_name end as f_intl_media,
    case when f_name = "VIP" then f_name end as f_vip,
    case when f_name = "Music_industry" then f_name end as f_music_industry,
    case when f_name = "senegal" then f_name end as f_senegal,
    case when f_name = "Music_Freedom_Day" then f_name end as f_music_freedom_day,
    case when f_name = "Scholar/student" then f_name end as f_scholar_student,
    case when f_name = "Anniversary_booklet" then f_name end as f_anniversary_booklet,
    case when f_name = "Music_industry" then f_name end as f_music_industry,
    case when f_name = "Old_membership" then f_name end as f_old_membership,
    case when f_name = "2wc" then f_name end as f_2wc,
    case when f_name = "Advisory_Board" then f_name end as f_advisory_board,
    case when f_name = "Danish_media" then f_name end as f_danish_media,
    case when f_name = "Business_contacts" then f_name end as f_business_contacts,
    case when f_name = "Latest_Report" then f_name end as f_latest_report,
    case when f_name = "Press_Alert" then f_name end as f_press_alert,
    case when f_name = "Funding/sponsor" then f_name end as f_funding_sponsor,
    case when f_name = "Diverse/Contacts" then f_name end as f_diverse_contacts,
    case when f_name = "Honorary_membership" then f_name end as f_honorary_membership,
    case when f_name = "Supporting_Membership" then f_name end as f_supporting_membership,
    case when f_name = "GA_2008" then f_name end as f_ga_2008,
    case when f_name = "Stringer" then f_name end as f_stringer,
    case when f_name = "Seminar" then f_name end as f_seminar,
    case when f_name = "Ambassador" then f_name end as f_ambassador,
    case when f_name = "1wc" then f_name end as f_1wc,
    case when f_name = "Evaluation Contacts" then f_name end as f_evaluation_contacts,
    case when f_name = "OIC_APPEAL" then f_name end as f_oic_appeal,
    case when f_name = "Paying membership" then f_name end as f_paying_membership,
    case when f_name = "Executive committee" then f_name end as f_executive_committee,
    case when f_name = "Institutional membership" then f_name end as f_institutional_membership
  from ahbtest1

);

行をIDで結合しようとすると、これが

select id, name, group_concat(fname)
  from table
  group by id,
4

1 に答える 1