How we can merge same row with exact count using MySQL?

前端 未结 2 850
灰色年华
灰色年华 2021-01-27 20:40

I have output like this:

number      pd_team  rating         att_attorney      law_firm                  patent_developer
496486      Networks  Auto                      


        
相关标签:
2条回答
  • 2021-01-27 21:10

    You could start with this...

    SELECT number entity
         , 'pd_team'  attribute 
         , pd_team value
      FROM my_table
     UNION
    SELECT number
         , 'rating'  attribute 
         , rating value
      FROM my_table
     UNION ...
    

    Deriving the results from this would be trivial

    0 讨论(0)
  • 2021-01-27 21:18

    Try this query.

    select t1.name Value, count(t1.name) Count from(
        select pd_team from Table
        union all
        select rating from Table
        union all
        select att_attorney from Table
        union all
        select law_firm from Table
        union all
        select patent_developer from Table) t1 group by t1.name;
    
    0 讨论(0)
提交回复
热议问题