如何将其转换为宽转置格式?
Id Food price Date
1 K 200 2017-01-02
2 L 150 2017-01-02
3 M 110 2017-01-02
没有使用枢轴而没有硬编码?
我无法弄清楚如何不对此进行硬编码。硬编码将是:
select Date,
max(if(Food='K', 200, null)) as FoodA,
max(if(Food='L', 150, null)) as FoodB,
max(if(Food='M', 110, null)) as FoodC
from table
group by Date