[英]MYSQL - Pivoting Data
UNION ALL
是一种很好的方法,但是它确实需要为每个子查询扫描一次表。
一种选择是使用cross join
。 这需要更多的编码,但是可能会加快速度:
select tt.task,
(case when tt.task = 'Use Proper PPE' then use_proper_ppe
when tt.task = 'Damage Prevention' then damage_prevention
. . .
end) as result
from t cross join
(select 'Use Proper PPE' as task union all
select 'Damage Prevention' union all
. . .
) tt;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.