sql 列转行-pivot

将table_1表中的数据,每个area的每个atype为A、B、C、D的数量统计出来。
重要的点:
---- 1)pivot()里面for前面必须用聚合函数;
---- 2)m字表中的每个字段都会在查询结果里面;

select * from 
    (select area,atype from table_1) m
    pivot (count(1) for atype in ('A','B','C','D'))
    order by area; 
posted @ 2023-07-25 16:11  Shilo  阅读(26)  评论(0编辑  收藏  举报