更新时间:2022-06-13 02:17:05
这只是条件聚合:
select pn, sum(loc = 'a') as a, sum(loc = 'b') as b
from table1
group by pn;
如果您有loc
值的未知列表,则可能需要动态查询. Google"MySQL动态枢纽".
If you have an unknown list of loc
values, then you might need a dynamic query. Google "MySQL dynamic pivot".