代码之家  ›  专栏  ›  技术社区  ›  davidzxc574

MySQL crosstab统计属于类别的id的数量

  •  0
  • davidzxc574  · 技术社区  · 5 年前

    ID_Cat 下面显示每个属于哪个类别的ID。某些ID可以属于多个类别。

    enter image description here

    我想做一个 crosstab 像矩阵一样计算并填写ID的计数,如下所示。

    enter image description here

    select count(*) into Int_Count
    from 
    ( 
    select ID_Member,count(distinct Cat_Name)
    from ID_Cat
    where Cat_Name='Cat1'
    group by ID_Member
    having count(distinct Cat)=1
    ) t;
    
    update crosstab
    set Cat1=In_count
    where Cat_name='Cat1';
    
    0 回复  |  直到 5 年前